Set was replaced with priority queue. Refactoring