Improving migration function