fix thread-safety issues with lock stuff