Refactor HTML generation