Added basic error handling for api.js as well as better api key handling.