some refactoring on environment management