Clean up broken sql queries. Account for db in config.