updated sql, cleanup