Refactor dom.js