Various bug fixes. Still need to fix SNES linesearch diverges.