Fixed document.evaluate scope & some null/undefined checks