Add support for multiple env states

Fixes #1087