fix doctype substring issue, use inner joins