thread race condition fixed