editted thread functions.