Tried an implementation of an unknown number of nested loops, based on:
    http://stackoverflow.com/questions/9555864/variable-nested-for-loops