If I understand the code correctly, it is this part of the code that does not behave as expected.
If so, I suggest that you read (and learn from ) Robin's updated Serial Input Basics; example 2 or 3 for starters.
The problem is that your code executes faster than the data comes in. So the E
might still be in transmission and not completely received. If you collect the data first (as demonstrated in above link), you will not have the problem.