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
Merge pull request #123 from leourbina/master

Refactors _group_by_module to avoid non-determinism and do correct grouping