now i have an inefficent algorithm AND race conditions