tightened up matrix functions