fixed the index error