Backport better way of sourcing env vars. Closes #306.