refactoring + added json output format support