Refactored media code
Code cleanup and some changes in ui