Fixed a pretty heinous bug with gradient computation, so now things work a lot better.