Refactoring resource logic