refactor contingency matrix