Refactor of the reindex command