Refactored out invariant generation