fixed an endless loop when length of chars is a divisor of 256