Encode direct keys before encoding keys that create their own tables