reworked serial communication to be more robust

reworked the serial communication to be more robust
made all changes from review