Serial.read() and Serial.available() are working not as expected in the code

Oi! I got an idea.
How about taking a look at this:
Serial - Arduino Reference

And the thingies about serial.begin and serial.end ? Might be onto something?