Rafactoring and improving CPU logic