fixed the index exception