Rewrite function to fully migrate data