Refactor static HTML to dynamic templates