Refactors setEnvironment to a class method