Complete refactoring for lxml