Skipping query input if key.length is 0. Added check for distinct input.
Removed toArray on distinct call.