WIP refactoring code from MediaBundle