race conditions fixed