Added some new qcost optimization stuff