Updated template fuctions with completed functions for caching and returning matrix inverses