added matrix implementation