fix some resource leaks