refactor javascript

remove some dependencies on the DOM