Added check matrix index function