Modified cachematrix.R script by Binselam