Refactored to have a generate_output method