Updated the logic for migration