Cleaned up sql