Added functions for calculating and storing cached matrix inverse