renamed and updated sql