Added error handling for no API or no connection