added thread state stuff