refactored helper function for peano multiplication