Fixing mistakes in matrix generation