Updated qcost calculation