MSPriorityQueue refactoring, bug fix