Fixing out of bounds error in char_dist code