Fix error on migration of fresh database
A number of small flexibility improvements