database query fix