Fixed a few resource leaks