Minor changes in error catching
Enhanced media type detection
Streamlined main loop