refactored output formatting and file logging