reorganization and better get env handling