Fix accumulatedWeight and iterate priorities in the right order.