Modified cachematrix.R for Coursera assignment 2 (016)