Refactored ENV handling