Fixed a lot of resource leaks