Some housekeeping and cleanup on resource management