Refactoring, mostly in OS and thread management
Refactoring to threading framework