Now also correctly extracts the last chapter of a pdf or the last child of a parent