Edited cahematrix.R with the required functionality