fix the bug of deleting the last element of a list