Slight refactoring. Improving efficiency using lodash.