Refactor cpu code.