refactored mime type detection