added emulator and added better exception handling