first implementation for cachematrix