fixed bad escaping and local var setting