Moved the resource creation logic into a factory.
added first partial.