Well, there’s your problem. You have a different number of matrix() calls per run() call when you must guarantee the same number of matrix() calls every time.
Restructure it so that you guarantee a fixed number of matrix() calls for every run() call.