refactor mime stuf