make it work with strings of arbitrary length