try removing items from the keys dict as we go, and delete any still left at the end