add check before pop and top