made detecting file types more robust