Replace array by global variables; add condition on ticks
merge changes