fixed extension detection code