added thread source code provided by prof.hanna