Fix queue sorting order fixes #1120

I also fixed indentation of the last if