added resource wrap, refactoring