Refactor the env setup script and put it at the top