cleaned up sql a little