First version of cached matrix functions.
Adding more comments.