Refactor getenv access

Another alternative to PR #6 and #7 including the idea of @bobthecow.