Refactored format code