Scope variables to specific emit

If second emit was called before first had finished, it fell over.
Merge pull request #10 from kevadsett/patch-1

Scope variables to specific emit