Fixes race condition.
Fixes crashes.