fix resource leaks