Added thread existence check