Check cached matrix

Add code to check if cached matrix has been altered before using cached
data