huge refactoring to support more powerful xpath