Further matrix code cleanup