tried to optimize performance by using a boolean matrix
fixed binary matrixes
reduced running through matrix once