queue as a procedure with local state