fix matrix functions