Add option to split by class/module + cleanup

Great suggestion and I even uncovered some bugs/weird behaviors while refactoring.

This code will split at the class level even if the module specifies no splitting, but that's fixed in the next commit.