Fixed DegeneracySorter. Added unit test.