Improve handling of the input string

And also use idiomatic Python to implement the autocomplete class.