Do refactoring.

Code modified according to comment and today lection