correct implementation of matrix bounds