refactored and cleaned up media import