fix algorithm: cost is negative priority