Need help shrinking a code
There is only one "while loop inside a while loop" and that is hardly complex:

while (Serial.available() == false) {}


All that means is "Wait for something to become available on the serial".  That is ALL it does.

There is nothing even remotely complex there.  True, it may not be very well written (as is the case with lots of code on t'interwebs).  It's time to start learning how the code works so you can write your own.