refactor complete, now passed nestest (upto illegal opcodes)