Working emulator (will need lots of tweaking)