I think we should combine the device/emulator logic. The two code blocks are basically identical.