added function to reindex the array