I don't understand what this line is for.  I don't think it makes any sense at all.  Even if you need to remove something from the array, there is no way you could know that it is the last element of the array to remove.  Please check this.