Fix broken data export. Needs tests, refactoring and requirements.