Fixes #1, a potential race condition.