Edited cachematrix function code. Working sample