factored out DOM manipulation