initial merge of migration code, minus tests