updated final with kkt conditions