changing loop to break on success