Sorting bug

This pull request fixes #1