refactored onfail repeation