two functions which pass a matrix between them for cacheing