matrix dimension bug fixed