changed to check for env violation every iteration