This is a race-condition. There should be a better way of doing this.