escape quotes and fix variables