use a queue

more safety and cleanup
Merge pull request #110 from Floobits/threadsafety

[Ready?] Threadsafety