Refactor ref selection, and handle new anchor data format.