Factor out Clock and fix lurking integer overflow bug