Fix and finish creation of matrix