Revamped emulator code