use stack instead of queue