Critical race-condition fixed