Refactored the entire output