refactor and ENV functionality