Updated set_max_length() function to actually pull a substring of the current text so it's not all thrown away when the new max length is shorter than the current length.