fixed a possible race condition