small changes to the sql query