changed resouce manage scoping.
fixed bug introduced in previous commit.