refactored cpu and io threads to use single function