improved migration script