Clean up sql code