refactor some Program functionality into Environment#build_sources()