Added class invariant checks
Fixed invalid buffer length caught by invariant checking
More invariant checks, fixed another invariant violation