Added reindexing function