some race conditions fixed