refactoring old code...
divided code to some functions. 1C very lean language. Had to use global variables to transfer data between functions %)