fixed race condition
Merge pull request #18 from mariokostelac/issue17

fixed race condition (resolves #17)