Fixed scope issues of serial port functions