priority queue + refactorings