Completely rewrite emulator