Improve migration code (with feedback and benchmarks)