Refactors _group_by_module to avoid non-determinism and do correct grouping

Fixes issue #100. Sorts items by name prior to groupby to obtain
correct groups