implemented functionallity to cache matrix inverse