fixes some multithread bug