small changes to thread safety