Fix replug shutdown crash.

Fixes #22 and tests when a device is plugged in.

I'm still not happy with the close/open code since it returns before things are really ready/shtudown, but this fixes any known issues.