implement better beginning-of-string function