Fixed the timer functions.

Before this fix, there was a bug in the timer functions which led to
timers being scheduled from within a timer functions being
forgotten. This change fixes that.