added invariant checks and malicious behavior