Improve file extension detection