Fixes race condition