incorporated diagonal gradient into general third order optimization code