add array boundary check when removing last item