Fix time handling bugs