refactoring data printing code