CacheMatrix implementation. Calculations should work properly