Rewrite polling logic to avoid multiple API calls