Tweaks to clean up matrix code.