More defensive parsing of matrix