osx improvements

Additions for error handling and debugging purposes. Modifications to make the script function better on slow serial-usb connections.

Please note that this still takes like 20 minutes to complete on osx, but at least it completes. The underlying osx problems are probably related to libusb, and I'm looking into that.