I'm not quite sure how to do this, at the moment mhw_ds is a fairly long function. Suggestions on if and how to cut it down in smaller chunks would be good.
The following functions which are used in mhw_ds are covered by tests already:
categories, group_function, get_peak, index_cat