Factor the metadata management.
Fix wrong variable name.
Fix incomplete refactoring.