made sql queries more generic