updated logic for flatten
the data method