Many resource management fixes