improve resource management function