Intermediate changes: use new Matrix module. Fix some silly bugs.