Fix copying into wrong position in matrix