improved retry and error handling