added function for matrix