Metadata events: fixes and refactoring