Refactor emulator core into importable library