Refactored HTML writing