Fixed strings escaping in SQL output, and sped up some code.