modified thread.c