implement emit and add testing code