Refactor CPU code