Avoid unsigned Compare to int

Cast arithmetic results to avoid comparison of an unsigned to an int.
Fix signed/unsigned Compare

Do some casting to avoid a signed/unsigned compare.