Attempt to merge some changes from xpath branch