reworked serial communication to be more robust