fix signed/unsigned comparisons
fix signed/unsigned comparisons, use prefix increment consistently