cleanup, simplify locking code