Tried to fix a few resource leaks