fix resource cleanup