Move retry logic in a func.