fix index checking