fixed resource leaking issue.