some code refactoring in dom.js