Updated cachematrix.R with correct program logic