Corrected time keeping code