Fixing bug in Thread class