fixed resource leaks