Refactoring reference interpreter (part 3)

Also performed some regression testing. One bug was unearthed and fixed,
otherwise behaviour is equivalent to the non-refactored interpreter.