Issues with Serial Read and write

To bring a bit of good luck, you should also check for i > 3 and take an appropriate action.