made it work for strings not divisible by 3