bugfix & code improve for cpu.c