rewrote migration routine logic