improved invertstring