code beautified for thread non block open process