Any reason why you're using result.remove(kv) instead of result.remove(idx)? The latter doesn't require a search and comparison.