some more refactoring. Prepare use of general methods for CSV and JSON generation.