added functions to operate with cached matrices
Added some comments and cleaned up