Fixing flag race condition. Resolves #12.