add some error handling to db connect and query function