refactor, now supports multiple environments, not just two