Scope variables to specific emit

If second emit was called before first had finished, it fell over.