Fix bugs in timer implementation