Completed code for caching inverse matrix