Fix bugs relating relation handling.