Refactored HTML generator code