corrected out of index error