added thread stopping code