refactored code for supporting more output formats