added tmpdir, fixed sub id
fixed escaping
dollar sign escape too