Reorganized some code, thread scheduler WIP
Reorganized some code, thread scheduler WIP