Fix 'comparison of integers of different signs' warnings.

Detected with -Wsign-compare.
Fix warning about unused function.