Simplifies db query function