fix messed up sql