Hopefully fix some ' escaping issues in sql output. Minor cleanups.