Refactoring environment loading