Move all of the custom timer stuff into a separate function and optimize a little.