Fix data races, simplify
Merge pull request #2 from titanous/fix-races

Fix data races, simplify