Fix bugs in serial connection