Reduce duplication in init-env code and clean up its interface.