added higher order function for matrix processing, kind of went overboard with lambdas, but it is fun