Refactor datatype and tracking for invariants to enable future work