Fixed a lot of memory leaks and improved error handling
Fixed another memory leak and a crash
Merge remote-tracking branch 'upstream/master'