Few enhancements to dom.js. See #870 #871 #872