Andrew's final solution for cachematrix.R