A bit of refactoring and checking that a resource is valid