Handle errors in API calls a little better. Make API available externally