refactored cpu.c