fixed a race condition(hopfully)