Fixed using of global variables

there was no reset after the first execution so erverything started
getting interesting...