much simpler/better factored retry function.