More 'index out of bounds' fixes and matrix-related problems