added code for caching inverse of matrix