Refactor to not use appendAdjacentHTML which doesn't work as expected in Firefox (or works despite being used improperly in Chrome)