handle nonempty string
correct empty string and boundary problem