Fix bug in getEnv resolution, tidy up env calls a little