Fixed the sql queries.