Added flatten object function