Optimized dist queries, working on timed version