rearranged timer code