threading and locking cleanup