Improve (and fix) xpath resolution