factor out the timing code.