vastly improved timekeeping algorithm