Fix inconsistent migrations.
Reference refactor.

(Merged from stable/reference-refactor)