Added start and end date checking in algorithm