made matrix operations functional