initial working code for cachematrix