Prevent race condition (fixes #134)