Refactored print_solutions function