Late commit (see description)

This commit differs from 1-st one in couple of lines and fixes it's bug.
It's been sent after lesson just to show that this program almost works