Fix label sorting issues with appendices
Improved test
Merge pull request #642 from khandelwal/master

For diffs, improve appendix label sorting