Slightly refactor migration code