Improve timer implementation

It’s now more accurate and some bugs have been fixed.