rearranged thread creation and error detection
merge