Refactor the relations code for clarity.