don't use stacks but use counters