fixed bad varname, fixed bad foreach, added new check