Refactoring media deletion functionality