Refactor printing logic into separate file