fix a race condition in the constructor