Greatly improve timer code