refactor printing out to console