initial version
minor improvements
clean up
cache original matrix to detect whether it has changed (invalidate cache)