completed and validated code for cachematrix.R