bug fix for removing last element