fixed potential race condition