Improved handling of text input