Nearly finished HTML generation code