Fixes to matrix math.