Moved migrate to a function