Improved file type detection