fix shifting queue, some refactoring