Fix issue with date ranges, code cleanup