Fix timer issue, and general code cleanup.