Added API key. Corrected error handling.