adds error handling for missing environments
adds missing conditional for missing environment handling