This commit includes code for relation validation (not yet fully tested).