Refactored to add support for resources (useful for test fixtures)