fixed off-by-one in removeAndInvalidate()