refactor of emulator