Modularize library

Relation-related assertions were getting big in implementation and test.
Break it up!