abstracted it out more, now works for multidimensional data sets