Fixed non-working matrix-reading code