Further refactoring of HTML generating code