mv dedup code and make responses outside of the critical section . And  also, refactor the dedup code into a function.
Merge pull request #80 from fanngyuan/master

refracter code