Some closure magic

Change some variable names to stop the parser getting confused by a closure.
Also realise that the matrix retrieved from cache must be copied in place.