fixed: clear up bugs introduced by changing matrix format to Fortran

also used K instead of N in the matrix initializing loop