refactor setup logic for midgard-portable