Refactored code to use jQuery native each function rather than _.each.
Refactored some code.