Js logic clean-up and underscore.js