refactor and prepare for other output formats