added Thread code