Added pretty printer and small refactoring.