simplifying code using _.each