Refactoring HTML rendering logic.