Refactored a lot of the html generation to make it more reusable