Thread locking fixes