Refactored timer code