added better handling of failed cases