misc bug fixes with locking