added stable code to read and write serial comm