Fixed queue iterator and added sorting support