Made sql queries more generic