Added support for grouping

The implemented grouping functionality enables grouping (up to n levels of sub-grouping).
It is implemented in one single method to avoid messing with the rest of the code and reuse most of what exists.
Three tests have been added to provide evidence.
Upon running the tests I noticed no (apparent) difference in the time it takes to run them all.
Even if it's not the best way to do it, it's a start and a helping hand.