Refactored: Extracted method for outputting HTML