Internal refactor to a format function