Enhance media field UI and remove duplicate code.