The rebuildIndex() method of this class is very similar and I think you can extract the parts that are almost the same into a common method