Fix resource management.