Eliminate a few unnecessary calculations in the maintenance loop.

Also uses wait event instead of sleep for periodicity control.