Refactoring, better env handling