Closed a few resource leaks.