Fix issues with missing closing tag, code duplication, etc.