Refactor of xmlhttprequest.js