Fixed function that checks file extension