My initial solution for this was to sleep 20*x milliseconds in setButton. Because the later random sleep is up to 10 milliseconds this ensures that the operations are always done in the defined order.
But I guess that's not what they were after, the solution was indeed as simple as:
z.Ybpx()
qrsre z.Haybpx()