matrix code improvements