Refactored HTML generation