fix locking and cpu churning issues