updated loop and date time logic