added code for v4 upgrade and updated code according to recent migration changes