refactored and cleaned output formatting