refactoring migration code