Bug fixes in matrix concatenation