refactors the cleaning away from the indexing