some restructuring of thread stuff