reworked a couple SQL