various fixes in the migration logic