Fix race conditions, but bug persists