fixing race conditions