Added function to flatten object