#466 Fix distinct handling