Refactored reference update

This PR refactors some of the node reference logic, having no effect on the behavior but making things clearer and also preparing the way for when Doctrine DBAL will support bulk inserts.