FIX #971, FIX #811 - Better magic file detection