Fixes race conditions