Refactored the processRelations routine into multiple functions