Improving Thread State Handling

Change-Id: Ibd0cc52af59dd58eafb671ec057de5357524a090