changed the timing to prevent rounding errors, and other bugs