Prevent some resource leaks