Refactored HTML generation code a little