Fixes potential race condition