Simplified timer logic and added comments.