Reduce the code duplication in timer handling code.