added assert/panic for invariants