Refactoring resourcehandling