Simplifying harder statements to easier more understandable code

Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

What parts are you having trouble with?

The way that you read serial input could use improvement. Have a look at the serial input basics tutorial.