Modified location function from lang so that if the offset is equal to the document's length then it returns the location for the last node.