handling api_key
Better exception handling