fixed bug caused when dividing by zero after base switch
fixed mod by zero after base switch