Code cleaning and better file type guessing.