Result output refactored into a function