Clean up and optimize handling of html element

Updated and cleaned up per Alex's suggestion for how to handle the html element when cleaning up classes