refactor the retry implementation.