class TimeRange and some refactors