restructuring and adding retries