Massive refactoring for easy html output