Added exceptions to dist_* functions for empty queries.