Updated funstions for time handling