rewrite to include more lodash functions and be easier to maintain