refactored cpu code