Fixed multithreading issues with gradients
Fixed leaks and uninitialized variables
Fixed a bunch of typos.