Silenced more sign-compare warnings and optimized the affected loop
conditions.