fix bugs; improve serial protocol