working functions of cachematrix.R