improve escaping of user paths

remove usage of if and () blocks as they clashed with user paths containing ()
postpone quotation of variables to prevent double escaping ("")
fix #3906