Fix race conditions.
Refactor timer.