Updated with finding NAs. Fixed reset of wd in pdfscript.