Added a validation to ensure the correct size of the matrix