Discharge optimization and the control of edge stability