Updated pruneRelationships method