Better handling of error cases, and made the API less self-contained (so that it can be used in a composite USB device, for example)