Extrapolated api error handling, cleaned up everything.