Delete relations that become empty

Fixes #465
Fixes #1454