refactored data export.
fixed several issues because of refactoring.