Added sorting of keys and a map reduce-style query function