add flags and make data-race-free