fix data races
Merge pull request #51 from tobstar87/racefix

fix data races