Redid the initial sql queries