optimize cpu code
improve tests