local emu refactoring and bugfix.