modify according to comments, add more synchronization control