Use thread safe functions and fix return values