Improved package sorting
Coding style compliance
Merge remote-tracking branch 'olvlvl/improved_package_sorting_alone'
Fix mode and add docblock, refs #2644