Fixed bugs in delay timer code, and refactored it.

Programming when exhausted just makes more work for yourself...