Refactor logic for detecting type of SAM file based on tags.