Made Sql queries more generic