Fix invariant violation

Fixes #321