refeactor startTime query generation code