Tweak the implementation for nested keys and add documentation