even better error message if directory does not exists
save keys in keydir (sorted set)
cleanup: move medeaiterator to own file