Use underscore.js where possible.
Some refactoring.