Improved the implementation of PriorityQueue internals. Temporary fix for #337