Refactor build_resource