Fixing html close logic