added start date and end date and flatten functionality