locking impl. and various cleanups