Refactor media management