Various corrections to avoid "signed/unsigned mismatch" warnings during compilation