Refactor main_wrap out to core.