Fix bug: pop elements when the container is emtpy.