Added first order necessary condition check