add thread states and move thread tasks to their respective files