refactor method that generates HTML string to instead append elements to DOM