replaced queue with stack