Implemented text/json outputs, some refactoring