Modified code to allow for sub objects to export in csv