Merge pull request #11 from NeoRaider/fixes

A few fixes for race conditions and similar problems