Handles API errors more gracefully, fixes issue #28