stateful iterator class