add checks to db query