refactoring print method