Changed the sql queries