adds validity checks for internal consistency.