Your code does not show what is calling these functions. This is critical. run() in fact must be calling matrix() the same exact number of times every time and we have zero information about that. Reread the error code description I supplied for clues. Or post the full code.