Refactored environment loading.