Kinda late on this, but instead of using a switch for handling by opcode, you can also use an array of handler objects. That makes it alot more organized in my opinion.
Hey thanks for the answer. Could you explain what do you mean by handler objects and how would I use them?