adding -o option and imrpoving thread syncro