Simplified timer function using ternary operator