Better way of doing the timer function.