some changes, aimed to make program more understadable.