some cleanup
Added locking