Lock race condition fixed