Add queue sorting and test.