finally fixed the matrix generation. damn u pointers