adding protection against race conditions