Refactored format function and improved presentation