Moving all API error handling stuff here
Fixing bugs and handling waits to avoid hitting the limit