Refactored environment manager script