Add sanity checks.  e.g. "if(!istype(environment)) return"