writing more because i can't sleep. I haven't tested any of the code inside handleInstruction, but hopefully this is useful.