refactor queue reordering from solution