Update test and fix bug in endOffset