preety printing + some refactoring