refactor resource handling