Added custom sort functionality. Finally fixes #1.