various fixes in utils.js

revealed by linting

- remove duplicate WrappedError definition
- remove various unused or double-declared variables
- fix some incorrect regex escaping
- add missing quotes in $('body')
- don't use assignment in while expression
We can't rely on JS `for ... in`, can we?