Refactor format()