fix bug of not popping stack when done