Refactoring with support for env vars.