added loop on fail logic