use critical sections properly