Fixing unsigned/signed mixup. Variables only used as indexes, so it's OK