refactored usb code