third and second order optimization