Refactor a bunch of structure logic out into irval.cpp.