migration script related fixes
added check to avoid stackoverflow with global constant refs