diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -76,3 +76,9 @@
 ## 0.6.0.1 -- 2023-09-04
 
 * Fixed documentation for readSAM_V1_6.
+
+## 0.7.0.0 -- 2023-10-16
+
+* Fixed broken parsing of SAM_V1_6(..).
+* Strengthened parsing of SAM_V1_6(..) by accurately emulating the sam v1.6 specification through use of permutable parsers.
+* Added initial test suite.
diff --git a/hs-samtools.cabal b/hs-samtools.cabal
--- a/hs-samtools.cabal
+++ b/hs-samtools.cabal
@@ -20,7 +20,7 @@
 -- PVP summary:     +-+------- breaking API changes
 --                  | | +----- non-breaking API additions
 --                  | | | +--- code changes with no API change
-version:            0.6.0.1
+version:            0.7.0.0
 
 -- A short (one-line) description of the package.
 synopsis: Read and write SAM, BAM, and CRAM files.
@@ -131,7 +131,7 @@
     -- other-extensions:
 
     -- Other library packages from which modules are imported.
-    build-depends:    base                 ^>=4.17.1.0,
+    build-depends:    base                 ^>=4.17.1.0, 
                       ascii                >= 1.7.0 && < 1.8,
                       attoparsec           >= 0.14.4 && < 0.15,
                       bitvec               >= 1.1.4 && < 1.2,
@@ -139,6 +139,7 @@
                       containers           >= 0.6.7 && < 0.7,
                       crypton              >= 0.33 && < 0.34,
                       generic-deriving     >= 1.14.5 && < 1.15,
+                      parser-combinators   >= 1.3.0 && < 1.4,
                       pcre-heavy           >= 1.0.0 && < 1.1,
                       regex-tdfa           >= 1.3.2 && < 1.4,
                       streamly             >= 0.9.0 && < 0.10,
@@ -174,7 +175,8 @@
     main-is:          Main.hs
 
     -- Test dependencies.
-    build-depends:
-        base ^>=4.17.1.0,
-        hspec == 2.11.4,
-        hs-samtools
+    build-depends: base ^>=4.17.1.0,
+                   bytestring,
+                   containers,
+                   hspec,
+                   hs-samtools
diff --git a/src/Data/SAM/Version1_6/Alignment/BOPT.hs b/src/Data/SAM/Version1_6/Alignment/BOPT.hs
--- a/src/Data/SAM/Version1_6/Alignment/BOPT.hs
+++ b/src/Data/SAM/Version1_6/Alignment/BOPT.hs
@@ -69,6 +69,27 @@
                                                        }
   deriving (Generic,Typeable)
 
+instance Eq SAM_V1_6_Alignment_BOPT where
+  SAM_V1_6_Alignment_BOPT sam_v1_6_alignment_bopt_int81
+                          sam_v1_6_alignment_bopt_word81
+                          sam_v1_6_alignment_bopt_int161
+                          sam_v1_6_alignment_bopt_word161
+                          sam_v1_6_alignment_bopt_int321
+                          sam_v1_6_alignment_bopt_word321
+                          sam_v1_6_alignment_bopt_float1 == SAM_V1_6_Alignment_BOPT sam_v1_6_alignment_bopt_int82
+                                                                                    sam_v1_6_alignment_bopt_word82
+                                                                                    sam_v1_6_alignment_bopt_int162
+                                                                                    sam_v1_6_alignment_bopt_word162
+                                                                                    sam_v1_6_alignment_bopt_int322
+                                                                                    sam_v1_6_alignment_bopt_word322
+                                                                                    sam_v1_6_alignment_bopt_float2 = sam_v1_6_alignment_bopt_int81   == sam_v1_6_alignment_bopt_int82   &&
+                                                                                                                     sam_v1_6_alignment_bopt_word81  == sam_v1_6_alignment_bopt_word82  &&
+                                                                                                                     sam_v1_6_alignment_bopt_int161  == sam_v1_6_alignment_bopt_int162  &&
+                                                                                                                     sam_v1_6_alignment_bopt_word161 == sam_v1_6_alignment_bopt_word162 &&
+                                                                                                                     sam_v1_6_alignment_bopt_int321  == sam_v1_6_alignment_bopt_int322  &&
+                                                                                                                     sam_v1_6_alignment_bopt_word321 == sam_v1_6_alignment_bopt_word322 &&
+                                                                                                                     sam_v1_6_alignment_bopt_float1  == sam_v1_6_alignment_bopt_float2
+
 instance Show SAM_V1_6_Alignment_BOPT where
   show (SAM_V1_6_Alignment_BOPT int8
                                 word8
diff --git a/src/Data/SAM/Version1_6/Alignment/Base.hs b/src/Data/SAM/Version1_6/Alignment/Base.hs
--- a/src/Data/SAM/Version1_6/Alignment/Base.hs
+++ b/src/Data/SAM/Version1_6/Alignment/Base.hs
@@ -111,6 +111,57 @@
                                              }
   deriving (Generic,Typeable)
 
+instance Eq SAM_V1_6_Alignment where
+  SAM_V1_6_Alignment sam_v1_6_alignment_qname1
+                     sam_v1_6_alignment_flag1
+                     sam_v1_6_alignment_rname1
+                     sam_v1_6_alignment_pos1
+                     sam_v1_6_alignment_mapq1
+                     sam_v1_6_alignment_cigar1
+                     sam_v1_6_alignment_rnext1
+                     sam_v1_6_alignment_pnext1
+                     sam_v1_6_alignment_tlen1
+                     sam_v1_6_alignment_seq1
+                     sam_v1_6_alignment_qual1
+                     sam_v1_6_alignment_aopt1
+                     sam_v1_6_alignment_iopt1
+                     sam_v1_6_alignment_fopt1
+                     sam_v1_6_alignment_zopt1
+                     sam_v1_6_alignment_hopt1
+                     sam_v1_6_alignment_bopt1 == SAM_V1_6_Alignment sam_v1_6_alignment_qname2
+                                                                    sam_v1_6_alignment_flag2
+                                                                    sam_v1_6_alignment_rname2
+                                                                    sam_v1_6_alignment_pos2
+                                                                    sam_v1_6_alignment_mapq2
+                                                                    sam_v1_6_alignment_cigar2
+                                                                    sam_v1_6_alignment_rnext2
+                                                                    sam_v1_6_alignment_pnext2
+                                                                    sam_v1_6_alignment_tlen2
+                                                                    sam_v1_6_alignment_seq2
+                                                                    sam_v1_6_alignment_qual2
+                                                                    sam_v1_6_alignment_aopt2
+                                                                    sam_v1_6_alignment_iopt2
+                                                                    sam_v1_6_alignment_fopt2
+                                                                    sam_v1_6_alignment_zopt2
+                                                                    sam_v1_6_alignment_hopt2
+                                                                    sam_v1_6_alignment_bopt2 = sam_v1_6_alignment_qname1 == sam_v1_6_alignment_qname2 &&  
+                                                                                               sam_v1_6_alignment_flag1  == sam_v1_6_alignment_flag2  &&
+                                                                                               sam_v1_6_alignment_rname1 == sam_v1_6_alignment_rname2 &&
+                                                                                               sam_v1_6_alignment_pos1   == sam_v1_6_alignment_pos2   &&
+                                                                                               sam_v1_6_alignment_mapq1  == sam_v1_6_alignment_mapq2  &&
+                                                                                               sam_v1_6_alignment_cigar1 == sam_v1_6_alignment_cigar2 &&
+                                                                                               sam_v1_6_alignment_rnext1 == sam_v1_6_alignment_rnext2 &&
+                                                                                               sam_v1_6_alignment_pnext1 == sam_v1_6_alignment_pnext2 &&
+                                                                                               sam_v1_6_alignment_tlen1  == sam_v1_6_alignment_tlen2  &&
+                                                                                               sam_v1_6_alignment_seq1   == sam_v1_6_alignment_seq2   &&
+                                                                                               sam_v1_6_alignment_qual1  == sam_v1_6_alignment_qual2  &&
+                                                                                               sam_v1_6_alignment_aopt1  == sam_v1_6_alignment_aopt2  &&
+                                                                                               sam_v1_6_alignment_iopt1  == sam_v1_6_alignment_iopt2  &&
+                                                                                               sam_v1_6_alignment_fopt1  == sam_v1_6_alignment_fopt2  &&
+                                                                                               sam_v1_6_alignment_zopt1  == sam_v1_6_alignment_zopt2  &&
+                                                                                               sam_v1_6_alignment_hopt1  == sam_v1_6_alignment_hopt2  &&
+                                                                                               sam_v1_6_alignment_bopt1  == sam_v1_6_alignment_bopt2
+
 instance Show SAM_V1_6_Alignment where
   show (SAM_V1_6_Alignment qname flag rname pos mapq cigar rnext pnext tlen seq qual aopt iopt fopt zopt hopt bopt) =
     "SAM_V1_6_Alignment { " ++
diff --git a/src/Data/SAM/Version1_6/Base.hs b/src/Data/SAM/Version1_6/Base.hs
--- a/src/Data/SAM/Version1_6/Base.hs
+++ b/src/Data/SAM/Version1_6/Base.hs
@@ -57,6 +57,24 @@
                          }
   deriving (Generic,Typeable)
 
+instance Eq SAM_V1_6 where
+  SAM_V1_6 sam_v1_6_file_level_metadata1
+           sam_v1_6_reference_sequence_dictionary1
+           sam_v1_6_read_group1
+           sam_v1_6_program1
+           sam_v1_6_one_line_comment1
+           sam_v1_6_alignment1 == SAM_V1_6 sam_v1_6_file_level_metadata2
+                                           sam_v1_6_reference_sequence_dictionary2
+                                           sam_v1_6_read_group2
+                                           sam_v1_6_program2
+                                           sam_v1_6_one_line_comment2
+                                           sam_v1_6_alignment2 = sam_v1_6_file_level_metadata1           == sam_v1_6_file_level_metadata2           &&
+                                                                 sam_v1_6_reference_sequence_dictionary1 == sam_v1_6_reference_sequence_dictionary2 &&
+                                                                 sam_v1_6_read_group1                    == sam_v1_6_read_group2                    &&
+                                                                 sam_v1_6_program1                       == sam_v1_6_program2                       &&
+                                                                 sam_v1_6_one_line_comment1              == sam_v1_6_one_line_comment2              &&
+                                                                 sam_v1_6_alignment1                     == sam_v1_6_alignment2
+
 instance Show SAM_V1_6 where
   show (SAM_V1_6 file_level_metadata
                  reference_sequence_dictionary
diff --git a/src/Data/SAM/Version1_6/Header/HD.hs b/src/Data/SAM/Version1_6/Header/HD.hs
--- a/src/Data/SAM/Version1_6/Header/HD.hs
+++ b/src/Data/SAM/Version1_6/Header/HD.hs
@@ -45,6 +45,18 @@
                                                                  }
    deriving (Generic,Typeable)
 
+instance Eq SAM_V1_6_File_Level_Metadata where
+  SAM_V1_6_File_Level_Metadata sam_v1_6_file_level_metadata_format_version1
+                               sam_v1_6_file_level_metadata_sorting_order1
+                               sam_v1_6_file_level_metadata_alignment_grouping1
+                               sam_v1_6_file_level_metadata_subsorting_order1 == SAM_V1_6_File_Level_Metadata sam_v1_6_file_level_metadata_format_version2
+                                                                                                              sam_v1_6_file_level_metadata_sorting_order2
+                                                                                                              sam_v1_6_file_level_metadata_alignment_grouping2
+                                                                                                              sam_v1_6_file_level_metadata_subsorting_order2 = sam_v1_6_file_level_metadata_format_version1     == sam_v1_6_file_level_metadata_format_version2     &&
+                                                                                                                                                               sam_v1_6_file_level_metadata_sorting_order1      == sam_v1_6_file_level_metadata_sorting_order2      &&
+                                                                                                                                                               sam_v1_6_file_level_metadata_alignment_grouping1 == sam_v1_6_file_level_metadata_alignment_grouping2 &&
+                                                                                                                                                               sam_v1_6_file_level_metadata_subsorting_order1   == sam_v1_6_file_level_metadata_subsorting_order2
+
 instance Show SAM_V1_6_File_Level_Metadata where
   show (SAM_V1_6_File_Level_Metadata version sorting_order alignment_grouping subsorting_order) =
     "SAM_V1_6_File_Level_Metadata { " ++
diff --git a/src/Data/SAM/Version1_6/Header/PG.hs b/src/Data/SAM/Version1_6/Header/PG.hs
--- a/src/Data/SAM/Version1_6/Header/PG.hs
+++ b/src/Data/SAM/Version1_6/Header/PG.hs
@@ -49,6 +49,24 @@
                                          }
   deriving (Generic,Typeable)
 
+instance Eq SAM_V1_6_Program where
+  SAM_V1_6_Program sam_v1_6_program_record_identifier1
+                   sam_v1_6_program_name1
+                   sam_v1_6_program_command_line1
+                   sam_v1_6_program_previous_pg_id1
+                   sam_v1_6_program_description1
+                   sam_v1_6_program_version1 == SAM_V1_6_Program sam_v1_6_program_record_identifier2
+                                                                 sam_v1_6_program_name2
+                                                                 sam_v1_6_program_command_line2
+                                                                 sam_v1_6_program_previous_pg_id2
+                                                                 sam_v1_6_program_description2
+                                                                 sam_v1_6_program_version2 = sam_v1_6_program_record_identifier1 == sam_v1_6_program_record_identifier2 &&
+                                                                                             sam_v1_6_program_name1              == sam_v1_6_program_name2              &&
+                                                                                             sam_v1_6_program_command_line1      == sam_v1_6_program_command_line2      &&
+                                                                                             sam_v1_6_program_previous_pg_id1    == sam_v1_6_program_previous_pg_id2    &&
+                                                                                             sam_v1_6_program_description1       == sam_v1_6_program_description2       &&
+                                                                                             sam_v1_6_program_version1           == sam_v1_6_program_version2
+
 instance Show SAM_V1_6_Program where
   show (SAM_V1_6_Program record_identifier name command_line previous_pg_id description version) =
     "SAM_V1_6_Program { "    ++
diff --git a/src/Data/SAM/Version1_6/Header/RG.hs b/src/Data/SAM/Version1_6/Header/RG.hs
--- a/src/Data/SAM/Version1_6/Header/RG.hs
+++ b/src/Data/SAM/Version1_6/Header/RG.hs
@@ -64,6 +64,48 @@
                                                , sam_v1_6_read_group_sample                       :: Maybe SAM_V1_6_Read_Group_Sample
                                                }
 
+instance Eq SAM_V1_6_Read_Group where
+  SAM_V1_6_Read_Group sam_v1_6_read_group_identifier1
+                      sam_v1_6_read_group_barcode_sequence1
+                      sam_v1_6_read_group_sequencing_center1
+                      sam_v1_6_read_group_description1
+                      sam_v1_6_read_group_run_date1
+                      sam_v1_6_read_group_flow_order1
+                      sam_v1_6_read_group_key_sequence1
+                      sam_v1_6_read_group_library1
+                      sam_v1_6_read_group_programs1
+                      sam_v1_6_read_group_predicted_median_insert_size1
+                      sam_v1_6_read_group_platform1
+                      sam_v1_6_read_group_platform_model1
+                      sam_v1_6_read_group_platform_unit1
+                      sam_v1_6_read_group_sample1 == SAM_V1_6_Read_Group sam_v1_6_read_group_identifier2
+                                                                         sam_v1_6_read_group_barcode_sequence2
+                                                                         sam_v1_6_read_group_sequencing_center2
+                                                                         sam_v1_6_read_group_description2
+                                                                         sam_v1_6_read_group_run_date2
+                                                                         sam_v1_6_read_group_flow_order2
+                                                                         sam_v1_6_read_group_key_sequence2
+                                                                         sam_v1_6_read_group_library2
+                                                                         sam_v1_6_read_group_programs2
+                                                                         sam_v1_6_read_group_predicted_median_insert_size2
+                                                                         sam_v1_6_read_group_platform2
+                                                                         sam_v1_6_read_group_platform_model2
+                                                                         sam_v1_6_read_group_platform_unit2
+                                                                         sam_v1_6_read_group_sample2 = sam_v1_6_read_group_identifier1                    == sam_v1_6_read_group_identifier2                    &&
+                                                                                                       sam_v1_6_read_group_barcode_sequence1             == sam_v1_6_read_group_barcode_sequence2             &&
+                                                                                                       sam_v1_6_read_group_sequencing_center1            == sam_v1_6_read_group_sequencing_center2            &&
+                                                                                                       sam_v1_6_read_group_description1                  == sam_v1_6_read_group_description2                  &&
+                                                                                                       sam_v1_6_read_group_run_date1                     == sam_v1_6_read_group_run_date2                     &&
+                                                                                                       sam_v1_6_read_group_flow_order1                   == sam_v1_6_read_group_flow_order2                   &&
+                                                                                                       sam_v1_6_read_group_key_sequence1                 == sam_v1_6_read_group_key_sequence2                 &&
+                                                                                                       sam_v1_6_read_group_library1                      == sam_v1_6_read_group_library2                      &&
+                                                                                                       sam_v1_6_read_group_programs1                     == sam_v1_6_read_group_programs2                     &&
+                                                                                                       sam_v1_6_read_group_predicted_median_insert_size1 == sam_v1_6_read_group_predicted_median_insert_size2 &&
+                                                                                                       sam_v1_6_read_group_platform1                     == sam_v1_6_read_group_platform2                     &&
+                                                                                                       sam_v1_6_read_group_platform_model1               == sam_v1_6_read_group_platform_model2               &&
+                                                                                                       sam_v1_6_read_group_platform_unit1                == sam_v1_6_read_group_platform_unit2                &&
+                                                                                                       sam_v1_6_read_group_sample1                       == sam_v1_6_read_group_sample2
+
 instance Show SAM_V1_6_Read_Group where
   show (SAM_V1_6_Read_Group group_identifier
                             barcode_sequence
diff --git a/src/Data/SAM/Version1_6/Header/SQ.hs b/src/Data/SAM/Version1_6/Header/SQ.hs
--- a/src/Data/SAM/Version1_6/Header/SQ.hs
+++ b/src/Data/SAM/Version1_6/Header/SQ.hs
@@ -57,6 +57,36 @@
                                                                                      }
   deriving (Generic,Typeable)
 
+instance Eq SAM_V1_6_Reference_Sequence_Dictionary where
+  SAM_V1_6_Reference_Sequence_Dictionary sam_v1_6_reference_sequence_dictionary_reference_sequence_name1
+                                         sam_v1_6_reference_sequence_dictionary_reference_sequence_length1
+                                         sam_v1_6_reference_sequence_dictionary_reference_alternative_locus1
+                                         sam_v1_6_reference_sequence_dictionary_reference_alternative_reference_sequence_names1
+                                         sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier1
+                                         sam_v1_6_reference_sequence_dictionary_description1
+                                         sam_v1_6_reference_sequence_dictionary_md5_checksum1
+                                         sam_v1_6_reference_sequence_dictionary_species1
+                                         sam_v1_6_reference_sequence_dictionary_molecule_topology1
+                                         sam_v1_6_reference_sequence_dictionary_uri1 == SAM_V1_6_Reference_Sequence_Dictionary sam_v1_6_reference_sequence_dictionary_reference_sequence_name2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_reference_sequence_length2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_reference_alternative_locus2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_reference_alternative_reference_sequence_names2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_description2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_md5_checksum2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_species2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_molecule_topology2
+                                                                                                                               sam_v1_6_reference_sequence_dictionary_uri2 = sam_v1_6_reference_sequence_dictionary_reference_sequence_name1                        == sam_v1_6_reference_sequence_dictionary_reference_sequence_name2                        &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_reference_sequence_length1                      == sam_v1_6_reference_sequence_dictionary_reference_sequence_length2                      &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_reference_alternative_locus1                    == sam_v1_6_reference_sequence_dictionary_reference_alternative_locus2                    &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_reference_alternative_reference_sequence_names1 == sam_v1_6_reference_sequence_dictionary_reference_alternative_reference_sequence_names2 &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier1                     == sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier2                     &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_description1                                    == sam_v1_6_reference_sequence_dictionary_description2                                    &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_md5_checksum1                                   == sam_v1_6_reference_sequence_dictionary_md5_checksum2                                   &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_species1                                        == sam_v1_6_reference_sequence_dictionary_species2                                        &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_molecule_topology1                              == sam_v1_6_reference_sequence_dictionary_molecule_topology2                              &&
+                                                                                                                                                                             sam_v1_6_reference_sequence_dictionary_uri1                                            == sam_v1_6_reference_sequence_dictionary_uri2
+
 instance Show SAM_V1_6_Reference_Sequence_Dictionary where
   show (SAM_V1_6_Reference_Sequence_Dictionary reference_sequence_name
                                                reference_sequence_length
diff --git a/src/Data/SAM/Version1_6/Read/Base.hs b/src/Data/SAM/Version1_6/Read/Base.hs
--- a/src/Data/SAM/Version1_6/Read/Base.hs
+++ b/src/Data/SAM/Version1_6/Read/Base.hs
@@ -1,16 +1,7 @@
-{-# LANGUAGE DeriveDataTypeable    #-}
-{-# LANGUAGE DeriveGeneric         #-}
 {-# LANGUAGE FlexibleContexts      #-}
 {-# LANGUAGE FlexibleInstances     #-}
 {-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE OverloadedLists       #-}
-{-# LANGUAGE OverloadedStrings     #-}
-{-# LANGUAGE MultiWayIf            #-}
-{-# LANGUAGE PackageImports        #-}
-{-# LANGUAGE RecordWildCards       #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
-{-# Language QuasiQuotes           #-}
 
 -- |
 -- Module      :  Data.SAM.Version1_6.Read.Base
@@ -35,12 +26,13 @@
 import Data.SAM.Version1_6.Read.Parser.Header.CO.Base
 import Data.SAM.Version1_6.Read.Parser.Alignment.Base
 
-import Data.Attoparsec.ByteString.Char8  as DABC8
+import Control.Applicative.Permutations                          (intercalateEffect,toPermutationWithDefault)
+import Data.Attoparsec.ByteString.Char8  as DABC8                (endOfLine)
 import Data.Attoparsec.ByteString.Lazy   as DABL
 import Data.ByteString.Lazy              as DBL
 import Data.Sequence                     as DSeq
 import qualified Streamly.Data.Stream    as S
-import Streamly.External.ByteString.Lazy as StreamlyLByteString (fromChunksIO)
+import Streamly.External.ByteString.Lazy as StreamlyLByteString  (fromChunksIO)
 import Streamly.Internal.FileSystem.File as StreamlyInternalFile (chunkReader)
 
 -- | Make a parser optional, return Nothing if there is no match.
@@ -51,36 +43,68 @@
 -- | Define the @"SAM_V1_6"@ parser.
 parse_SAM_V1_6 :: Parser SAM_V1_6
 parse_SAM_V1_6 = do
-  filelevelmetadata           <- maybeOption $ parse_SAM_V1_6_File_Level_Metadata <* endOfLine
-  _                           <- word8 10
-  referencesequencedictionary <- maybeOption $ DABL.many' $ parse_SAM_V1_6_Reference_Sequence_Dictionary <* endOfLine
-  _                           <- word8 10
-  readgroup                   <- maybeOption $ DABL.many' $ parse_SAM_V1_6_Read_Group <* endOfLine
-  _                           <- word8 10
-  program                     <- maybeOption $ parse_SAM_V1_6_Program <* endOfLine
-  _                           <- word8 10
-  onelinecomment              <- maybeOption $ DABL.many' $ parse_SAM_V1_6_One_Line_Comment <* endOfLine 
-  _                           <- word8 10
-  alignment                   <- DABL.many' $ parse_SAM_V1_6_Alignment <* endOfLine
-  return SAM_V1_6 { sam_v1_6_file_level_metadata           = filelevelmetadata
-                  , sam_v1_6_reference_sequence_dictionary = case referencesequencedictionary of
-                                                               Nothing                           -> Nothing
-                                                               Just referencesequencedictionaryf -> Just $ DSeq.fromList referencesequencedictionaryf
-                  , sam_v1_6_read_group                    = case readgroup of
-                                                               Nothing         -> Nothing
-                                                               Just readgroupf -> Just $ DSeq.fromList readgroupf
-                  , sam_v1_6_program                       = program
-                  , sam_v1_6_one_line_comment              = case onelinecomment of
-                                                               Nothing              -> Nothing
-                                                               Just onelinecommentf -> Just $ DSeq.fromList onelinecommentf
-                  , sam_v1_6_alignment                     = DSeq.fromList alignment
-                  } 
+  filelevelmetadata <- maybeOption parse_SAM_V1_6_File_Level_Metadata
+  case filelevelmetadata of
+    Nothing  -> do samwoalignment <- intercalateEffect endOfLine $
+                                       (,,,)
+                                         <$> toPermutationWithDefault Nothing
+                                                                      (Just <$> DABL.many1' parse_SAM_V1_6_Reference_Sequence_Dictionary)
+                                         <*> toPermutationWithDefault Nothing
+                                                                      (Just <$> DABL.many1' parse_SAM_V1_6_Read_Group)
+                                         <*> toPermutationWithDefault Nothing
+                                                                      (Just <$> parse_SAM_V1_6_Program)
+                                         <*> toPermutationWithDefault Nothing
+                                                                      (Just <$> DABL.many1' parse_SAM_V1_6_One_Line_Comment)
+                   alignment <- DABL.many1' parse_SAM_V1_6_Alignment
+                   return SAM_V1_6 { sam_v1_6_file_level_metadata           = Nothing
+                                   , sam_v1_6_reference_sequence_dictionary = (\(a,_,_,_) -> case a of
+                                                                                               Nothing      -> Nothing
+                                                                                               Just finala  -> Just $ DSeq.fromList finala
+                                                                              ) samwoalignment
+                                   , sam_v1_6_read_group                    = (\(_,b,_,_) -> case b of
+                                                                                               Nothing      -> Nothing
+                                                                                               Just finalb  -> Just $ DSeq.fromList finalb
+                                                                              ) samwoalignment
+                                   , sam_v1_6_program                       = (\(_,_,c,_) -> c) samwoalignment
+                                   , sam_v1_6_one_line_comment              = (\(_,_,_,d) -> case d of
+                                                                                               Nothing      -> Nothing
+                                                                                               Just finald  -> Just $ DSeq.fromList finald
+                                                                              ) samwoalignment
+                                   , sam_v1_6_alignment                     = DSeq.fromList alignment
+                                   }
+    Just flm -> do samwoalignment <- intercalateEffect endOfLine $
+                                       (,,,)
+                                         <$> toPermutationWithDefault Nothing
+                                                                      (Just <$> DABL.many1' parse_SAM_V1_6_Reference_Sequence_Dictionary)
+                                         <*> toPermutationWithDefault Nothing
+                                                                      (Just <$> DABL.many1' parse_SAM_V1_6_Read_Group)
+                                         <*> toPermutationWithDefault Nothing
+                                                                      (Just <$> parse_SAM_V1_6_Program)
+                                         <*> toPermutationWithDefault Nothing
+                                                                      (Just <$> DABL.many1' parse_SAM_V1_6_One_Line_Comment)
+                   alignment <- DABL.many1' parse_SAM_V1_6_Alignment
+                   return SAM_V1_6 { sam_v1_6_file_level_metadata           = Just flm
+                                   , sam_v1_6_reference_sequence_dictionary = (\(a,_,_,_) -> case a of
+                                                                                               Nothing      -> Nothing
+                                                                                               Just finala  -> Just $ DSeq.fromList finala
+                                                                              ) samwoalignment
+                                   , sam_v1_6_read_group                    = (\(_,b,_,_) -> case b of
+                                                                                               Nothing      -> Nothing
+                                                                                               Just finalb  -> Just $ DSeq.fromList finalb
+                                                                              ) samwoalignment
+                                   , sam_v1_6_program                       = (\(_,_,c,_) -> c) samwoalignment
+                                   , sam_v1_6_one_line_comment              = (\(_,_,_,d) -> case d of
+                                                                                               Nothing      -> Nothing
+                                                                                               Just finald  -> Just $ DSeq.fromList finald
+                                                                              ) samwoalignment
+                                   , sam_v1_6_alignment                     = DSeq.fromList alignment
+                                   }
 
 -- | Run the @"SAM_V1_6"@ parser.
 readSAM_V1_6_LBS :: DBL.ByteString
                  -> IO SAM_V1_6
 readSAM_V1_6_LBS lbs =
-  case (DABL.parseOnly parse_SAM_V1_6 lbs) of
+  case (DABL.parseOnly parse_SAM_V1_6 lbs) of 
     Left  samparseerror -> error samparseerror
     Right sam           -> return sam
 
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Alignment/AOPT.hs b/src/Data/SAM/Version1_6/Read/Parser/Alignment/AOPT.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Alignment/AOPT.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Alignment/AOPT.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# Language QuasiQuotes           #-}
 
@@ -46,6 +45,7 @@
 
 import Data.SAM.Version1_6.Read.Error
 
+import           Data.Attoparsec.ByteString.Char8  as DABC8 (isEndOfLine)
 import           Data.Attoparsec.ByteString.Lazy   as DABL
 import qualified Data.ByteString                   as DB
 import           Text.Regex.PCRE.Heavy
@@ -57,19 +57,19 @@
 parse_SAM_V1_6_Alignment_AOPT = do
   _ <- do alignmentaoptfieldtagp <- DABL.takeTill (== 58)
           -- Parse AOPT tag of the alignment section.
-          case (alignmentaoptfieldtagp =~ [re|/[A-Za-z][A-Za-z0-9]/|]) of
+          case (alignmentaoptfieldtagp =~ [re|[A-Za-z][A-Za-z0-9]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_AOPT_Tag_Incorrect_Format
             True  -> -- AOPT tag is in the accepted format. 
-                     return alignmentaoptfieldtagp
+                     return ()
   _ <- word8 58
   _ <- do alignmentaoptfieldtypep <- DABL.takeTill (== 58)
           -- Parse AOPT type of the alignment section.
           case (alignmentaoptfieldtypep =~ [re|[A]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_AOPT_Type_Incorrect_Format
             True  -> -- AOPT type is in the accepted format.
-                     return alignmentaoptfieldtypep
+                     return ()
   _ <- word8 58
-  alignmentaoptfieldvalue <- do alignmentaoptfieldvaluep <- DABL.takeTill (== 09)
+  alignmentaoptfieldvalue <- do alignmentaoptfieldvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                 -- Parse AOPT value of the alignment section.
                                 case (alignmentaoptfieldvaluep =~ [re|[!-~]|]) of
                                   False -> fail $ show SAM_V1_6_Error_Alignment_AOPT_Value_Incorrect_Format
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Alignment/BOPT.hs b/src/Data/SAM/Version1_6/Read/Parser/Alignment/BOPT.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Alignment/BOPT.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Alignment/BOPT.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# Language QuasiQuotes           #-}
 
@@ -47,6 +46,7 @@
 import Data.SAM.Version1_6.Alignment.BOPT
 import Data.SAM.Version1_6.Read.Error
 
+import           Data.Attoparsec.ByteString.Char8  as DABC8 (isEndOfLine)
 import           Data.Attoparsec.ByteString.Lazy   as DABL
 import qualified Data.ByteString                   as DB (head,unpack)
 import qualified Data.ByteString.Char8             as DBC8
@@ -60,7 +60,7 @@
 parse_SAM_V1_6_Alignment_BOPT = do
   alignmentboptfieldtag <- do alignmentboptfieldtagp <- DABL.takeTill (== 58)
                               -- Parse BOPT tag of the alignment section.
-                              case (alignmentboptfieldtagp =~ [re|/[A-Za-z][A-Za-z0-9]/|]) of
+                              case (alignmentboptfieldtagp =~ [re|[A-Za-z][A-Za-z0-9]|]) of
                                 False -> fail $ show SAM_V1_6_Error_Alignment_BOPT_Tag_Incorrect_Format
                                 True  -> -- BOPT tag is in the accepted format. 
                                          return alignmentboptfieldtagp
@@ -70,7 +70,7 @@
           case (alignmentboptfieldtypep =~ [re|[B]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_BOPT_Type_Incorrect_Format
             True  -> -- BOPT type is in the accepted format.
-                     return alignmentboptfieldtypep
+                     return ()
   _ <- word8 58
   alignmentboptfieldvaluetype <- do alignmentboptfieldvaluetypep <- DABL.take 1
                                     -- Parse BOPT value type of the alignment section.
@@ -78,9 +78,10 @@
                                       False -> fail $ show SAM_V1_6_Error_Alignment_BOPT_Value_Type_Incorrect_Format
                                       True  -> -- BOPT value type is in the accepted format.
                                                return alignmentboptfieldvaluetypep
-  alignmentboptfieldvaluedata <- do alignmentboptfieldvaluedatap <- DABL.takeTill (\x -> x == 09 || x == 0x0D || x == 0x0A)
+  _ <- word8 44
+  alignmentboptfieldvaluedata <- do alignmentboptfieldvaluedatap <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                     -- Parse BOPT value data of the alignment section.
-                                    case (alignmentboptfieldvaluedatap =~ [re|(,[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)*|]) of
+                                    case (alignmentboptfieldvaluedatap =~ [re|([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)*|]) of
                                       False -> fail $ show SAM_V1_6_Error_Alignment_BOPT_Value_Data_Incorrect_Format
                                       True  -> -- BOPT value data is in the accepted format.
                                                return alignmentboptfieldvaluedatap
@@ -169,4 +170,4 @@
                                           , sam_v1_6_alignment_bopt_int32  = Nothing
                                           , sam_v1_6_alignment_bopt_word32 = Nothing
                                           , sam_v1_6_alignment_bopt_float  = Nothing
-                                          } 
+                                          }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Alignment/Base.hs b/src/Data/SAM/Version1_6/Read/Parser/Alignment/Base.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Alignment/Base.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Alignment/Base.hs
@@ -8,7 +8,6 @@
 {-# LANGUAGE MultiWayIf                  #-}
 {-# LANGUAGE PackageImports              #-}
 {-# LANGUAGE RecordWildCards             #-}
-{-# LANGUAGE TemplateHaskell             #-}
 {-# LANGUAGE TypeFamilies                #-}
 {-# Language QuasiQuotes                 #-}
 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
@@ -53,15 +52,12 @@
 import Data.SAM.Version1_6.Read.Parser.Alignment.HOPT
 import Data.SAM.Version1_6.Read.Parser.Alignment.BOPT
 
+import           Control.Applicative.Permutations           (intercalateEffect,toPermutationWithDefault)
+import           Data.Attoparsec.ByteString.Char8  as DABC8 (endOfLine,isEndOfLine)
 import           Data.Attoparsec.ByteString.Lazy   as DABL
 import qualified Data.ByteString.Char8             as DBC8
 import           Text.Regex.PCRE.Heavy
 
--- | Make a parser optional, return Nothing if there is no match.
-maybeOption :: Parser a
-            -> Parser (Maybe a)
-maybeOption p = option Nothing (Just <$> p)
-
 -- | @"SAM_V1_6_Alignment"@ parser.
 --
 -- Defines a parser for the alignment section of the SAM v1.6 file format.
@@ -78,28 +74,28 @@
   _ <- word8 09
   flag <- do flagp <- DABL.takeTill (== 09)
              -- Parse FLAG field of alignment section.
-             case (flagp =~ [re|[0-9]*|]) of
+             case (flagp =~ [re|[0-9]+|]) of
                False -> fail $ show SAM_V1_6_Error_Alignment_FLAG_Incorrect_Format
                True  -> -- FLAG is in the accepted format.
                         return flagp
   _ <- word8 09
   rname <- do rnamep <- DABL.takeTill (== 09)
               -- Parse RNAME field of alignment section.
-              case (rnamep =~ [re|\*|[0-9A-Za-z!#$%&+./:;?@^_|~-][0-9A-Za-z!#$%&*+./:;=?@^_|~-]*|]) of
+              case (rnamep =~ [re|\*|[0-9A-Za-z!#$%&+.:;?@^_|~-][0-9A-Za-z!#$%&*+.:;=?@^_|~-]*|]) of
                 False -> fail $ show SAM_V1_6_Error_Alignment_RNAME_Incorrect_Format 
                 True  -> -- RNAME is in the accepted format.
                          return rnamep
   _ <- word8 09
   pos <- do posp <- DABL.takeTill (== 09)
             -- Parse POS field of the alignment section.
-            case (posp =~ [re|[0-9]*|]) of
+            case (posp =~ [re|[0-9]+|]) of
               False -> fail $ show SAM_V1_6_Error_Alignment_POS_Incorrect_Format
               True  -> -- POS is in the accepted format.
                        return posp
   _ <- word8 09
   mapq <- do mapqp <- DABL.takeTill (== 09)
              -- Parse MAPQ field of the alignment section.
-             case (mapqp =~ [re|[0-9]*|]) of
+             case (mapqp =~ [re|[0-9]+|]) of
                False -> fail $ show SAM_V1_6_Error_Alignment_MAPQ_Incorrect_Format
                True  -> -- MAPQ is in the accepted format.
                         return mapqp
@@ -113,21 +109,21 @@
   _ <- word8 09
   rnext <- do rnextp <- DABL.takeTill (== 09)
               -- Parse RNEXT field of the alignment section.
-              case (rnextp =~ [re|\*|=|[0-9A-Za-z!#$%&+./:;?@^_|~-][0-9A-Za-z!#$%&*+./:;=?@^_|~-]*|]) of
+              case (rnextp =~ [re|\*|=|[0-9A-Za-z!#$%&+.:;?@^_|~-][0-9A-Za-z!#$%&*+.:;=?@^_|~-]*|]) of
                 False -> fail $ show SAM_V1_6_Error_Alignment_RNEXT_Incorrect_Format
                 True  -> -- RNEXT is in the accepted format.
                          return rnextp
   _ <- word8 09
   pnext <- do pnextp <- DABL.takeTill (== 09)
               -- Parse PNEXT field of the alignment section.
-              case (pnextp =~ [re|[0-9]*|]) of
+              case (pnextp =~ [re|[0-9]+|]) of
                 False -> fail $ show SAM_V1_6_Error_Alignment_PNEXT_Incorrect_Format
                 True  -> -- PNEXT is in the accepted format.
                          return pnextp
   _ <- word8 09
   tlen <- do tlenp <- DABL.takeTill (== 09)
              -- Parse TLEN field of the alignment section.
-             case (tlenp =~ [re|[-]?[0-9]*|]) of
+             case (tlenp =~ [re|[-]?[0-9]+|]) of
                False -> fail $ show SAM_V1_6_Error_Alignment_TLEN_Incorrect_Format 
                True  -> -- TLEN is in the accepted format.
                         return tlenp
@@ -139,53 +135,89 @@
               True  -> -- SEQ is in the accepted format.
                        return seqp
   _ <- word8 09
-  qual <- do qualp <- DABL.takeTill (== 09)
+  qual <- do qualp <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
              -- Parse QUAL field of the alignment section.
              case (qualp =~ [re|[!-~?]+|\*|]) of
                False -> fail $ show SAM_V1_6_Error_Alignment_QUAL_Incorrect_Format
                True  -> -- QUAL is in the accepted format.
-                        return qualp
-  _ <- word8 09
-  -- This parser assumes that the AOPT tag always appears first,
-  -- followed by IOPT, FOPT, ZOPT, HOPT, and BOPT, if they exist,
-  -- in that order.
-  aopt <- maybeOption parse_SAM_V1_6_Alignment_AOPT
-  _    <- word8 09
-  iopt <- maybeOption parse_SAM_V1_6_Alignment_IOPT
-  _    <- word8 09
-  fopt <- maybeOption parse_SAM_V1_6_Alignment_FOPT
-  _    <- word8 09
-  zopt <- maybeOption parse_SAM_V1_6_Alignment_ZOPT
-  _    <- word8 09
-  hopt <- maybeOption parse_SAM_V1_6_Alignment_HOPT
-  _    <- word8 09
-  bopt <- maybeOption parse_SAM_V1_6_Alignment_BOPT
-  -- Return the parsed SAM_V1_6.
-  return SAM_V1_6_Alignment { sam_v1_6_alignment_qname  = qname
-                            , sam_v1_6_alignment_flag   = case (DBC8.readInt flag) of
-                                                            Nothing          -> (-1)
-                                                            Just (flagint,_) -> flagint
-                            , sam_v1_6_alignment_rname = rname
-                            , sam_v1_6_alignment_pos   = case (DBC8.readInteger pos) of
-                                                           Nothing             -> 0
-                                                           Just (posinteger,_) -> posinteger
-                            , sam_v1_6_alignment_mapq  = case (DBC8.readInt mapq) of
-                                                           Nothing          -> 255
-                                                           Just (mapqint,_) -> mapqint
-                            , sam_v1_6_alignment_cigar = cigar
-                            , sam_v1_6_alignment_rnext = rnext
-                            , sam_v1_6_alignment_pnext = case (DBC8.readInteger pnext) of
-                                                           Nothing               -> 0
-                                                           Just (pnextinteger,_) -> pnextinteger
-                            , sam_v1_6_alignment_tlen  = case (DBC8.readInteger tlen) of
-                                                           Nothing              -> 0
-                                                           Just (tleninteger,_) -> tleninteger
-                            , sam_v1_6_alignment_seq   = seq
-                            , sam_v1_6_alignment_qual  = qual
-                            , sam_v1_6_alignment_aopt  = aopt
-                            , sam_v1_6_alignment_iopt  = iopt
-                            , sam_v1_6_alignment_fopt  = fopt
-                            , sam_v1_6_alignment_zopt  = zopt
-                            , sam_v1_6_alignment_hopt  = hopt
-                            , sam_v1_6_alignment_bopt  = bopt
-                            }
+                        return qualp 
+  optfields <- peekWord8
+  case optfields of
+    Just 10 -> do -- Return the parsed SAM_V1_6.
+                  _ <- endOfLine
+                  return SAM_V1_6_Alignment { sam_v1_6_alignment_qname  = qname
+                                            , sam_v1_6_alignment_flag   = case (DBC8.readInt flag) of
+                                                                            Nothing          -> (-1)
+                                                                            Just (flagint,_) -> flagint
+                                            , sam_v1_6_alignment_rname = rname
+                                            , sam_v1_6_alignment_pos   = case (DBC8.readInteger pos) of
+                                                                           Nothing             -> 0
+                                                                           Just (posinteger,_) -> posinteger
+                                            , sam_v1_6_alignment_mapq  = case (DBC8.readInt mapq) of
+                                                                           Nothing          -> 255
+                                                                           Just (mapqint,_) -> mapqint
+                                            , sam_v1_6_alignment_cigar = cigar
+                                            , sam_v1_6_alignment_rnext = rnext
+                                            , sam_v1_6_alignment_pnext = case (DBC8.readInteger pnext) of
+                                                                           Nothing               -> 0
+                                                                           Just (pnextinteger,_) -> pnextinteger
+                                            , sam_v1_6_alignment_tlen  = case (DBC8.readInteger tlen) of
+                                                                           Nothing              -> 0
+                                                                           Just (tleninteger,_) -> tleninteger
+                                            , sam_v1_6_alignment_seq   = seq
+                                            , sam_v1_6_alignment_qual  = qual
+                                            , sam_v1_6_alignment_aopt  = Nothing
+                                            , sam_v1_6_alignment_iopt  = Nothing
+                                            , sam_v1_6_alignment_fopt  = Nothing
+                                            , sam_v1_6_alignment_zopt  = Nothing
+                                            , sam_v1_6_alignment_hopt  = Nothing
+                                            , sam_v1_6_alignment_bopt  = Nothing
+                                            }
+    _       -> do -- This parser assumes that
+                  -- the AOPT, IOPT, FOPT, ZOPT, HOPT, and BOPT
+                  -- tags can appear in any order.
+                  _ <- word8 09
+                  optionalfields <- intercalateEffect (word8 09) $
+                                      (,,,,,)
+                                        <$> toPermutationWithDefault Nothing
+                                                                     (Just <$> parse_SAM_V1_6_Alignment_AOPT)
+                                        <*> toPermutationWithDefault Nothing
+                                                                     (Just <$> parse_SAM_V1_6_Alignment_IOPT)
+                                        <*> toPermutationWithDefault Nothing
+                                                                     (Just <$> parse_SAM_V1_6_Alignment_FOPT)
+                                        <*> toPermutationWithDefault Nothing
+                                                                     (Just <$> parse_SAM_V1_6_Alignment_ZOPT)
+                                        <*> toPermutationWithDefault Nothing
+                                                                     (Just <$> parse_SAM_V1_6_Alignment_HOPT)
+                                        <*> toPermutationWithDefault Nothing
+                                                                     (Just <$> parse_SAM_V1_6_Alignment_BOPT)
+                  _ <- endOfLine 
+                  -- Return the parsed SAM_V1_6.
+                  return SAM_V1_6_Alignment { sam_v1_6_alignment_qname  = qname
+                                            , sam_v1_6_alignment_flag   = case (DBC8.readInt flag) of
+                                                                            Nothing          -> (-1)
+                                                                            Just (flagint,_) -> flagint
+                                            , sam_v1_6_alignment_rname = rname
+                                            , sam_v1_6_alignment_pos   = case (DBC8.readInteger pos) of
+                                                                           Nothing             -> 0
+                                                                           Just (posinteger,_) -> posinteger
+                                            , sam_v1_6_alignment_mapq  = case (DBC8.readInt mapq) of
+                                                                           Nothing          -> 255
+                                                                           Just (mapqint,_) -> mapqint
+                                            , sam_v1_6_alignment_cigar = cigar
+                                            , sam_v1_6_alignment_rnext = rnext
+                                            , sam_v1_6_alignment_pnext = case (DBC8.readInteger pnext) of
+                                                                           Nothing               -> 0
+                                                                           Just (pnextinteger,_) -> pnextinteger
+                                            , sam_v1_6_alignment_tlen  = case (DBC8.readInteger tlen) of
+                                                                           Nothing              -> 0
+                                                                           Just (tleninteger,_) -> tleninteger
+                                            , sam_v1_6_alignment_seq   = seq
+                                            , sam_v1_6_alignment_qual  = qual
+                                            , sam_v1_6_alignment_aopt  = (\(a,_,_,_,_,_) -> a) optionalfields
+                                            , sam_v1_6_alignment_iopt  = (\(_,i,_,_,_,_) -> i) optionalfields
+                                            , sam_v1_6_alignment_fopt  = (\(_,_,f,_,_,_) -> f) optionalfields
+                                            , sam_v1_6_alignment_zopt  = (\(_,_,_,z,_,_) -> z) optionalfields
+                                            , sam_v1_6_alignment_hopt  = (\(_,_,_,_,h,_) -> h) optionalfields
+                                            , sam_v1_6_alignment_bopt  = (\(_,_,_,_,_,b) -> b) optionalfields
+                                            }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Alignment/FOPT.hs b/src/Data/SAM/Version1_6/Read/Parser/Alignment/FOPT.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Alignment/FOPT.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Alignment/FOPT.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# Language QuasiQuotes           #-}
 
@@ -46,6 +45,7 @@
 
 import Data.SAM.Version1_6.Read.Error
 
+import           Data.Attoparsec.ByteString.Char8  as DABC8 (isEndOfLine)
 import           Data.Attoparsec.ByteString.Lazy   as DABL
 import qualified Data.ByteString.Char8             as DBC8
 import           Text.Regex.PCRE.Heavy
@@ -57,19 +57,19 @@
 parse_SAM_V1_6_Alignment_FOPT = do
   _ <- do alignmentfoptfieldtagp <- DABL.takeTill (== 58)
           -- Parse FOPT tag of the alignment section.
-          case (alignmentfoptfieldtagp =~ [re|/[A-Za-z][A-Za-z0-9]/|]) of
+          case (alignmentfoptfieldtagp =~ [re|[A-Za-z][A-Za-z0-9]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_FOPT_Tag_Incorrect_Format
             True  -> -- FOPT tag is in the accepted format. 
-                     return alignmentfoptfieldtagp
+                     return ()
   _ <- word8 58
   _ <- do alignmentfoptfieldtypep <- DABL.takeTill (== 58)
           -- Parse FOPT type of the alignment section.
           case (alignmentfoptfieldtypep =~ [re|[f]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_FOPT_Type_Incorrect_Format
             True  -> -- FOPT type is in the accepted format.
-                     return alignmentfoptfieldtypep
+                     return ()
   _ <- word8 58
-  alignmentfoptfieldvalue <- do alignmentfoptfieldvaluep <- DABL.takeTill (== 09)
+  alignmentfoptfieldvalue <- do alignmentfoptfieldvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                 -- Parse FOPT value of the alignment section.
                                 case (alignmentfoptfieldvaluep =~ [re|[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?|]) of
                                   False -> fail $ show SAM_V1_6_Error_Alignment_FOPT_Value_Incorrect_Format
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Alignment/HOPT.hs b/src/Data/SAM/Version1_6/Read/Parser/Alignment/HOPT.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Alignment/HOPT.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Alignment/HOPT.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# Language QuasiQuotes           #-}
 
@@ -46,6 +45,7 @@
 
 import Data.SAM.Version1_6.Read.Error
 
+import           Data.Attoparsec.ByteString.Char8  as DABC8 (isEndOfLine)
 import           Data.Attoparsec.ByteString.Lazy   as DABL
 import qualified Data.ByteString                   as DB
 import           Data.Sequence                     as DSeq
@@ -59,19 +59,19 @@
 parse_SAM_V1_6_Alignment_HOPT = do
   _ <- do alignmenthoptfieldtagp <- DABL.takeTill (== 58)
           -- Parse HOPT tag of the alignment section.
-          case (alignmenthoptfieldtagp =~ [re|/[A-Za-z][A-Za-z0-9]/|]) of
+          case (alignmenthoptfieldtagp =~ [re|[A-Za-z][A-Za-z0-9]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_HOPT_Tag_Incorrect_Format
             True  -> -- HOPT tag is in the accepted format. 
-                     return alignmenthoptfieldtagp
+                     return ()
   _ <- word8 58
   _ <- do alignmenthoptfieldtypep <- DABL.takeTill (== 58)
           -- Parse HOPT type of the alignment section.
           case (alignmenthoptfieldtypep =~ [re|[H]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_HOPT_Type_Incorrect_Format
             True  -> -- HOPT type is in the accepted format.
-                     return alignmenthoptfieldtypep
+                     return ()
   _ <- word8 58
-  alignmenthoptfieldvalue <- do alignmenthoptfieldvaluep <- DABL.takeTill (== 09)
+  alignmenthoptfieldvalue <- do alignmenthoptfieldvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                 -- Parse HOPT value of the alignment section.
                                 case (alignmenthoptfieldvaluep =~ [re|([0-9A-F][0-9A-F])*|]) of
                                   False -> fail $ show SAM_V1_6_Error_Alignment_HOPT_Value_Incorrect_Format
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Alignment/IOPT.hs b/src/Data/SAM/Version1_6/Read/Parser/Alignment/IOPT.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Alignment/IOPT.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Alignment/IOPT.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# Language QuasiQuotes           #-}
 
@@ -46,6 +45,7 @@
 
 import Data.SAM.Version1_6.Read.Error
 
+import           Data.Attoparsec.ByteString.Char8  as DABC8 (isEndOfLine)
 import           Data.Attoparsec.ByteString.Lazy   as DABL
 import qualified Data.ByteString.Char8             as DBC8
 import           Text.Regex.PCRE.Heavy
@@ -57,19 +57,19 @@
 parse_SAM_V1_6_Alignment_IOPT = do
   _ <- do alignmentioptfieldtagp <- DABL.takeTill (== 58)
           -- Parse IOPT tag of the alignment section.
-          case (alignmentioptfieldtagp =~ [re|/[A-Za-z][A-Za-z0-9]/|]) of
+          case (alignmentioptfieldtagp =~ [re|[A-Za-z][A-Za-z0-9]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_IOPT_Tag_Incorrect_Format
             True  -> -- IOPT tag is in the accepted format. 
-                     return alignmentioptfieldtagp
+                     return ()
   _ <- word8 58
   _ <- do alignmentioptfieldtypep <- DABL.takeTill (== 58)
           -- Parse IOPT type of the alignment section.
           case (alignmentioptfieldtypep =~ [re|[i]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_IOPT_Type_Incorrect_Format
             True  -> -- IOPT type is in the accepted format.
-                     return alignmentioptfieldtypep
+                     return ()
   _ <- word8 58
-  alignmentioptfieldvalue <- do alignmentioptfieldvaluep <- DABL.takeTill (== 09)
+  alignmentioptfieldvalue <- do alignmentioptfieldvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                 -- Parse IOPT value of the alignment section.
                                 case (alignmentioptfieldvaluep =~ [re|[-+]?[0-9]+|]) of
                                   False -> fail $ show SAM_V1_6_Error_Alignment_IOPT_Value_Incorrect_Format
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Alignment/ZOPT.hs b/src/Data/SAM/Version1_6/Read/Parser/Alignment/ZOPT.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Alignment/ZOPT.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Alignment/ZOPT.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# Language QuasiQuotes           #-}
 
@@ -46,6 +45,7 @@
 
 import Data.SAM.Version1_6.Read.Error
 
+import           Data.Attoparsec.ByteString.Char8  as DABC8 (isEndOfLine)
 import           Data.Attoparsec.ByteString.Lazy   as DABL
 import qualified Data.ByteString                   as DB
 import           Text.Regex.PCRE.Heavy
@@ -57,19 +57,19 @@
 parse_SAM_V1_6_Alignment_ZOPT = do
   _ <- do alignmentzoptfieldtagp <- DABL.takeTill (== 58)
           -- Parse ZOPT tag of the alignment section.
-          case (alignmentzoptfieldtagp =~ [re|/[A-Za-z][A-Za-z0-9]/|]) of
+          case (alignmentzoptfieldtagp =~ [re|[A-Za-z][A-Za-z0-9]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_ZOPT_Tag_Incorrect_Format
             True  -> -- ZOPT tag is in the accepted format. 
-                     return alignmentzoptfieldtagp
+                     return ()
   _ <- word8 58
   _ <- do alignmentzoptfieldtypep <- DABL.takeTill (== 58)
           -- Parse ZOPT type of the alignment section.
           case (alignmentzoptfieldtypep =~ [re|[Z]|]) of
             False -> fail $ show SAM_V1_6_Error_Alignment_ZOPT_Type_Incorrect_Format
             True  -> -- ZOPT type is in the accepted format.
-                     return alignmentzoptfieldtypep
+                     return ()
   _ <- word8 58
-  alignmentzoptfieldvalue <- do alignmentzoptfieldvaluep <- DABL.takeTill (== 09)
+  alignmentzoptfieldvalue <- do alignmentzoptfieldvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                 -- Parse ZOPT value of the alignment section.
                                 case (alignmentzoptfieldvaluep =~ [re|[ !-~]*|]) of
                                   False -> fail $ show SAM_V1_6_Error_Alignment_ZOPT_Value_Incorrect_Format
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/CO/Base.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/CO/Base.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/CO/Base.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/CO/Base.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports              #-}
 {-# LANGUAGE RecordWildCards             #-}
 {-# LANGUAGE ScopedTypeVariables         #-}
-{-# LANGUAGE TemplateHaskell             #-}
 {-# LANGUAGE TypeFamilies                #-}
 {-# LANGUAGE QuasiQuotes                 #-}
 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
@@ -48,7 +47,7 @@
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import Data.Attoparsec.ByteString.Char8  as DABC8
+import Data.Attoparsec.ByteString.Char8  as DABC8 (endOfLine,isEndOfLine)
 import Data.Attoparsec.ByteString.Lazy   as DABL
 import Text.Regex.PCRE.Heavy
 
@@ -64,8 +63,9 @@
                   case (coheaderp =~ [re|[@][C][O]|]) of
                     False -> fail $ show SAM_V1_6_Error_One_Line_Comment_Tag_Incorrect_Format
                     True  -> -- @CO tag is in the accepted format.
-                             return coheaderp
+                             return ()
   _         <- word8 09
-  value     <- DABL.takeTill (\x -> x == 13 || x == 10)
+  value     <- DABL.takeTill isEndOfLine
+  _         <- endOfLine
   return SAM_V1_6_One_Line_Comment { sam_v1_6_one_line_comment_value = value
                                    }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/Base.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/Base.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/Base.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/Base.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -51,14 +50,11 @@
 import Data.SAM.Version1_6.Read.Parser.Header.HD.GO
 import Data.SAM.Version1_6.Read.Parser.Header.HD.SS
 
+import Control.Applicative.Permutations           (intercalateEffect,toPermutation,toPermutationWithDefault)
+import Data.Attoparsec.ByteString.Char8  as DABC8 (endOfLine)
 import Data.Attoparsec.ByteString.Lazy   as DABL
 import Text.Regex.PCRE.Heavy
 
--- | Make a parser optional, return Nothing if there is no match.
-maybeOption :: Parser a
-            -> Parser (Maybe a)
-maybeOption p = option Nothing (Just <$> p)
-
 -- | @"SAM_V1_6_File_Level_Metadata"@ parser.
 --
 -- Defines a parser for @HD tag section of the SAM v1.6 file format.
@@ -71,19 +67,18 @@
                   case (hdheaderp =~ [re|[@][H][D]|]) of
                     False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Tag_Incorrect_Format
                     True  -> -- @HD tag is in the accepted format.
-                             return hdheaderp
+                             return () 
   _         <- word8 09
-  -- This parser assumes that the VN tag always appears first, followed by
-  -- SO, GO and SS tags, if they exist, in that order.
-  vn <- parse_SAM_V1_6_File_Level_Metadata_VN
-  _  <- word8 09
-  so <- maybeOption parse_SAM_V1_6_File_Level_Metadata_SO
-  _  <- word8 09
-  go <- maybeOption parse_SAM_V1_6_File_Level_Metadata_GO
-  _  <- word8 09
-  ss <- maybeOption parse_SAM_V1_6_File_Level_Metadata_SS
-  return SAM_V1_6_File_Level_Metadata { sam_v1_6_file_level_metadata_format_version     = vn
-                                      , sam_v1_6_file_level_metadata_sorting_order      = so
-                                      , sam_v1_6_file_level_metadata_alignment_grouping = go
-                                      , sam_v1_6_file_level_metadata_subsorting_order   = ss
-                                      }
+  -- This parser assumes that the
+  -- VN, SO, GO and SS tags can appear in any order.
+  hd <- intercalateEffect (word8 09) $
+          SAM_V1_6_File_Level_Metadata
+            <$> toPermutation parse_SAM_V1_6_File_Level_Metadata_VN
+            <*> toPermutationWithDefault Nothing 
+                                         (Just <$> parse_SAM_V1_6_File_Level_Metadata_SO)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_File_Level_Metadata_GO)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_File_Level_Metadata_SS)
+  _ <- endOfLine
+  return hd 
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/GO.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/GO.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/GO.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/GO.hs
@@ -47,8 +47,9 @@
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the GO tag of the @HD tag section of the SAM v1.6 file format.
 --
@@ -60,9 +61,9 @@
           case (hdheaderalignmentgroupingtagp =~ [re|[G][O]|]) of
             False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Grouping_Of_Alignments_Tag_Incorrect_Format
             True  -> -- GO tag is in the accepted format.
-                     return hdheaderalignmentgroupingtagp
+                     return ()
   _ <- word8 58
-  hdheaderalignmentgroupingvalue <- do hdheaderalignmentgroupingvaluep <- DABL.takeTill (== 09)
+  hdheaderalignmentgroupingvalue <- do hdheaderalignmentgroupingvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                        -- Parse GO value of the header section.
                                        case (hdheaderalignmentgroupingvaluep =~ [re|[n][o][n][e]|[q][u][e][r][y]|[r][e][f][e][r][e][n][c][e]|]) of
                                          False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Grouping_Of_Alignments_Invalid_Value
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/SO.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/SO.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/SO.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/SO.hs
@@ -47,8 +47,9 @@
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the SO tag of the @HD tag section of the SAM v1.6 file format.
 --
@@ -60,9 +61,9 @@
           case (hdheadersortingordertagp =~ [re|[S][O]|]) of
             False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Sorting_Order_Tag_Incorrect_Format
             True  -> -- SO tag is in the accepted format.
-                     return hdheadersortingordertagp
+                     return ()
   _ <- word8 58
-  hdheadersortingordervalue <- do hdheadersortingordervaluep <- DABL.takeTill (== 09)
+  hdheadersortingordervalue <- do hdheadersortingordervaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                   -- Parse SO value of the header section.
                                   case (hdheadersortingordervaluep =~ [re|[u][n][k][n][o][w][n]|[u][n][s][o][r][t][e][d]|[q][u][e][r][y][n][a][m][e]|[c][o][o][r][d][i][n][a][t][e]|]) of
                                     False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Sorting_Order_Invalid_Value
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/SS.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/SS.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/SS.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/SS.hs
@@ -47,8 +47,9 @@
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the SS tag of the @HD tag section of the SAM v1.6 file format.
 --
@@ -60,9 +61,9 @@
           case (hdheadersubsortingordertagp =~ [re|[S][S]|]) of
             False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Subsorting_Order_Tag_Incorrect_Format
             True  -> -- SS tag is in the accepted format.
-                     return hdheadersubsortingordertagp
+                     return ()
   _ <- word8 58
-  hdheadersubsortingordervalue <- do hdheadersubsortingordervaluep <- DABL.takeTill (== 09)
+  hdheadersubsortingordervalue <- do hdheadersubsortingordervaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                      -- Parse SS value of the header section.
                                      case (hdheadersubsortingordervaluep =~ [re|(coordinate|queryname|unsorted)(:[A-Za-z0-9_-]+)+|]) of
                                        False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Subsorting_Order_Incorrect_Format 
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/VN.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/VN.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/HD/VN.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/HD/VN.hs
@@ -47,8 +47,9 @@
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the VN tag of the @HD tag section of the SAM v1.6 file format.
 --
@@ -60,11 +61,11 @@
           case (hdheaderversiontagp =~ [re|[V][N]|]) of
             False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Format_Version_Tag_Incorrect_Format
             True  -> -- VN tag is in the accepted format. 
-                     return hdheaderversiontagp
+                     return ()
   _ <- word8 58
-  hdheaderversionvalue <- do hdheaderversionvaluep <- DABL.takeTill (== 09)
+  hdheaderversionvalue <- do hdheaderversionvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                              -- Parse VN value of the header section.
-                             case (hdheaderversionvaluep =~ [re|/^[0-9]+\.[0-9]+$/.|]) of
+                             case (hdheaderversionvaluep =~ [re|^[0-9]+\.[0-9]+$|]) of
                                False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Format_Version_Value_Incorrect_Format
                                True  -> -- VN value is in the accepted format.
                                         return hdheaderversionvaluep  
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/Base.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/Base.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/Base.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/Base.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports              #-}
 {-# LANGUAGE RecordWildCards             #-}
 {-# LANGUAGE ScopedTypeVariables         #-}
-{-# LANGUAGE TemplateHaskell             #-}
 {-# LANGUAGE TypeFamilies                #-}
 {-# LANGUAGE QuasiQuotes                 #-}
 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
@@ -54,14 +53,11 @@
 import Data.SAM.Version1_6.Read.Parser.Header.PG.DS
 import Data.SAM.Version1_6.Read.Parser.Header.PG.VN
 
+import Control.Applicative.Permutations           (intercalateEffect,toPermutation,toPermutationWithDefault)
+import Data.Attoparsec.ByteString.Char8  as DABC8 (endOfLine)
 import Data.Attoparsec.ByteString.Lazy   as DABL
 import Text.Regex.PCRE.Heavy
 
--- | Make a parser optional, return Nothing if there is no match.
-maybeOption :: Parser a
-            -> Parser (Maybe a)
-maybeOption p = option Nothing (Just <$> p)
-
 -- | @"SAM_V1_6_Program"@ parser.
 --
 -- Defines a parser for @PG tag section of the SAM v1.6 file format.
@@ -74,26 +70,22 @@
                   case (pgheaderp =~ [re|[@][P][G]|]) of
                     False -> fail $ show SAM_V1_6_Error_Program_Tag_Incorrect_Format 
                     True  -> -- @PG tag is in the accepted format.
-                             return pgheaderp
+                             return ()
   _         <- word8 09
-  -- This parser assumes that the ID tag always appears first, followed by
-  -- the PN, CL, PP,
-  -- DS and VN tags if they exist, in that order.
-  id <- parse_SAM_V1_6_SAM_V1_6_Program_ID
-  _  <- word8 09
-  pn <- maybeOption parse_SAM_V1_6_SAM_V1_6_Program_PN
-  _  <- word8 09
-  cl <- maybeOption parse_SAM_V1_6_SAM_V1_6_Program_CL
-  _  <- word8 09
-  pp <- maybeOption parse_SAM_V1_6_SAM_V1_6_Program_PP
-  _  <- word8 09
-  ds <- maybeOption parse_SAM_V1_6_SAM_V1_6_Program_DS
-  _  <- word8 09
-  vn <- maybeOption parse_SAM_V1_6_SAM_V1_6_Program_VN
-  return SAM_V1_6_Program { sam_v1_6_program_record_identifier = id
-                          , sam_v1_6_program_name              = pn
-                          , sam_v1_6_program_command_line      = cl
-                          , sam_v1_6_program_previous_pg_id    = pp
-                          , sam_v1_6_program_description       = ds
-                          , sam_v1_6_program_version           = vn
-                          }
+  -- This parser assumes that the
+  -- ID, PN, CL, PP, DS, and VN tags can appear in any order.
+  pg <- intercalateEffect (word8 09) $
+          SAM_V1_6_Program
+            <$> toPermutation parse_SAM_V1_6_Program_ID
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Program_PN)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Program_CL)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Program_PP)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Program_DS)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Program_VN)
+  _ <- endOfLine
+  return pg
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/CL.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/CL.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/CL.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/CL.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.PG.CL ( -- * SAM_V1_6 parser - header section (Program) - CL tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Program_CL
+                                                      parse_SAM_V1_6_Program_CL
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the CL tag of the @PG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Program_CL :: Parser SAM_V1_6_Program_Command_Line
-parse_SAM_V1_6_SAM_V1_6_Program_CL = do
+parse_SAM_V1_6_Program_CL :: Parser SAM_V1_6_Program_Command_Line
+parse_SAM_V1_6_Program_CL = do
   _ <- do pgheadercommandlinetagp <- DABL.takeTill (== 58)
           -- Parse CL tag of the header section.
           case (pgheadercommandlinetagp =~ [re|[C][L]|]) of
             False -> fail $ show SAM_V1_6_Error_Program_Command_Line_Incorrect_Format 
             True  -> -- CL tag is in the accepted format. 
-                     return pgheadercommandlinetagp
+                     return ()
   _ <- word8 58
-  pgheadercommandlinevalue <- DABL.takeTill (== 09)
+  pgheadercommandlinevalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Program_Command_Line { sam_v1_6_program_command_line_value = pgheadercommandlinevalue
                                        }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/DS.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/DS.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/DS.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/DS.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.PG.DS ( -- * SAM_V1_6 parser - header section (Program) - DS tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Program_DS
+                                                      parse_SAM_V1_6_Program_DS
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the DS tag of the @PG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Program_DS :: Parser SAM_V1_6_Program_Description
-parse_SAM_V1_6_SAM_V1_6_Program_DS = do
+parse_SAM_V1_6_Program_DS :: Parser SAM_V1_6_Program_Description
+parse_SAM_V1_6_Program_DS = do
   _ <- do pgheaderdescriptiontagp <- DABL.takeTill (== 58)
           -- Parse DS tag of the header section.
           case (pgheaderdescriptiontagp =~ [re|[D][S]|]) of
             False -> fail $ show SAM_V1_6_Error_Program_Description_Incorrect_Format 
             True  -> -- DS tag is in the accepted format. 
-                     return pgheaderdescriptiontagp
+                     return ()
   _ <- word8 58
-  pgheaderdescriptionvalue <- DABL.takeTill (== 09)
+  pgheaderdescriptionvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Program_Description { sam_v1_6_program_description_value = pgheaderdescriptionvalue
                                       }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/ID.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/ID.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/ID.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/ID.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.PG.ID ( -- * SAM_V1_6 parser - header section (Program) - ID tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Program_ID
+                                                      parse_SAM_V1_6_Program_ID
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the ID tag of the @PG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Program_ID :: Parser SAM_V1_6_Program_Record_Identifier
-parse_SAM_V1_6_SAM_V1_6_Program_ID = do
+parse_SAM_V1_6_Program_ID :: Parser SAM_V1_6_Program_Record_Identifier
+parse_SAM_V1_6_Program_ID = do
   _ <- do pgheaderidentifiertagp <- DABL.takeTill (== 58)
           -- Parse ID tag of the header section.
           case (pgheaderidentifiertagp =~ [re|[I][D]|]) of
             False -> fail $ show SAM_V1_6_Error_Program_Identifier_Incorrect_Format 
             True  -> -- ID tag is in the accepted format. 
-                     return pgheaderidentifiertagp
+                     return ()
   _ <- word8 58
-  pgheaderidentifiervalue <- DABL.takeTill (== 09)
+  pgheaderidentifiervalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Program_Record_Identifier { sam_v1_6_program_record_identifier_value = pgheaderidentifiervalue
                                             }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/PN.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/PN.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/PN.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/PN.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.PG.PN ( -- * SAM_V1_6 parser - header section (Program) - PN tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Program_PN
+                                                      parse_SAM_V1_6_Program_PN
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the PN tag of the @PG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Program_PN :: Parser SAM_V1_6_Program_Name
-parse_SAM_V1_6_SAM_V1_6_Program_PN = do
+parse_SAM_V1_6_Program_PN :: Parser SAM_V1_6_Program_Name
+parse_SAM_V1_6_Program_PN = do
   _ <- do pgheadernametagp <- DABL.takeTill (== 58)
           -- Parse PN tag of the header section.
           case (pgheadernametagp =~ [re|[P][N]|]) of
             False -> fail $ show SAM_V1_6_Error_Program_Name_Incorrect_Format 
             True  -> -- PN tag is in the accepted format. 
-                     return pgheadernametagp
+                     return ()
   _ <- word8 58
-  pgheadernamevalue <- DABL.takeTill (== 09)
+  pgheadernamevalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Program_Name { sam_v1_6_program_name_value = pgheadernamevalue
                                }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/PP.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/PP.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/PP.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/PP.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.PG.PP ( -- * SAM_V1_6 parser - header section (Program) - PP tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Program_PP
+                                                      parse_SAM_V1_6_Program_PP
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the PP tag of the @PG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Program_PP :: Parser SAM_V1_6_Program_Previous_PG_ID
-parse_SAM_V1_6_SAM_V1_6_Program_PP = do
+parse_SAM_V1_6_Program_PP :: Parser SAM_V1_6_Program_Previous_PG_ID
+parse_SAM_V1_6_Program_PP = do
   _ <- do pgheaderpreviouspgidtagp <- DABL.takeTill (== 58)
           -- Parse PP tag of the header section.
           case (pgheaderpreviouspgidtagp =~ [re|[P][P]|]) of
             False -> fail $ show SAM_V1_6_Error_Program_Previous_PG_ID_Incorrect_Format 
             True  -> -- PP tag is in the accepted format. 
-                     return pgheaderpreviouspgidtagp
+                     return ()
   _ <- word8 58
-  pgheaderpreviouspgidvalue <- DABL.takeTill (== 09)
+  pgheaderpreviouspgidvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Program_Previous_PG_ID { sam_v1_6_program_previous_pg_id_value = pgheaderpreviouspgidvalue
                                          }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/VN.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/VN.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/PG/VN.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/PG/VN.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.PG.VN ( -- * SAM_V1_6 parser - header section (Program) - VN tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Program_VN
+                                                      parse_SAM_V1_6_Program_VN
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the VN tag of the @PG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Program_VN :: Parser SAM_V1_6_Program_Version
-parse_SAM_V1_6_SAM_V1_6_Program_VN = do
+parse_SAM_V1_6_Program_VN :: Parser SAM_V1_6_Program_Version
+parse_SAM_V1_6_Program_VN = do
   _ <- do pgheaderversiontagp <- DABL.takeTill (== 58)
           -- Parse VN tag of the header section.
           case (pgheaderversiontagp =~ [re|[V][N]|]) of
             False -> fail $ show SAM_V1_6_Error_Program_Version_Incorrect_Format 
             True  -> -- VN tag is in the accepted format. 
-                     return pgheaderversiontagp
+                     return ()
   _ <- word8 58
-  pgheaderversionvalue <- DABL.takeTill (== 09)
+  pgheaderversionvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Program_Version { sam_v1_6_program_version_value = pgheaderversionvalue
                                   }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/BC.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/BC.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/BC.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/BC.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.BC ( -- * SAM_V1_6 parser - header section (Read group) - BC tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_BC
+                                                      parse_SAM_V1_6_Read_Group_BC
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the BC tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_BC :: Parser SAM_V1_6_Read_Group_Barcode_Sequence 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_BC = do
+parse_SAM_V1_6_Read_Group_BC :: Parser SAM_V1_6_Read_Group_Barcode_Sequence 
+parse_SAM_V1_6_Read_Group_BC = do
   _ <- do rgheaderbarcodesequencetagp <- DABL.takeTill (== 58)
           -- Parse BC tag of the header section.
           case (rgheaderbarcodesequencetagp =~ [re|[B][C]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Barcode_Sequence_Incorrect_Format 
             True  -> -- BC tag is in the accepted format. 
-                     return rgheaderbarcodesequencetagp
+                     return ()
   _ <- word8 58
-  rgheaderbarcodesequencevalue <- DABL.takeTill (== 09)
+  rgheaderbarcodesequencevalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Barcode_Sequence { sam_v1_6_read_group_barcode_sequence_value = rgheaderbarcodesequencevalue
                                               }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/Base.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/Base.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/Base.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/Base.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports              #-}
 {-# LANGUAGE RecordWildCards             #-}
 {-# LANGUAGE ScopedTypeVariables         #-}
-{-# LANGUAGE TemplateHaskell             #-}
 {-# LANGUAGE TypeFamilies                #-}
 {-# LANGUAGE QuasiQuotes                 #-}
 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
@@ -62,14 +61,11 @@
 import Data.SAM.Version1_6.Read.Parser.Header.RG.PU
 import Data.SAM.Version1_6.Read.Parser.Header.RG.SM
 
+import Control.Applicative.Permutations           (intercalateEffect,toPermutation,toPermutationWithDefault)
+import Data.Attoparsec.ByteString.Char8  as DABC8 (endOfLine)
 import Data.Attoparsec.ByteString.Lazy   as DABL
 import Text.Regex.PCRE.Heavy
 
--- | Make a parser optional, return Nothing if there is no match.
-maybeOption :: Parser a
-            -> Parser (Maybe a)
-maybeOption p = option Nothing (Just <$> p)
-
 -- | @"SAM_V1_6_Read_Group"@ parser.
 --
 -- Defines a parser for @RG tag section of the SAM v1.6 file format.
@@ -82,50 +78,39 @@
                   case (rgheaderp =~ [re|[@][R][G]|]) of
                     False -> fail $ show SAM_V1_6_Error_Read_Group_Tag_Incorrect_Format
                     True  -> -- @RG tag is in the accepted format.
-                             return rgheaderp
+                             return ()
   _         <- word8 09
-  -- This parser assumes that the ID tag always appears first, followed by
-  -- the BC, CN, DS, DT, FO, KS, LB, PG, PI, PL,
-  -- PM, PU and SM tags if they exist, in that order.
-  id <- parse_SAM_V1_6_SAM_V1_6_Read_Group_ID
-  _  <- word8 09
-  bc <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_BC
-  _  <- word8 09
-  cn <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_CN
-  _  <- word8 09
-  ds <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_DS
-  _  <- word8 09
-  dt <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_DT
-  _  <- word8 09
-  fo <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_FO
-  _  <- word8 09
-  ks <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_KS
-  _  <- word8 09
-  lb <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_LB
-  _  <- word8 09
-  pg <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_PG
-  _  <- word8 09
-  pi <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_PI
-  _  <- word8 09
-  pl <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_PL
-  _  <- word8 09
-  pm <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_PM
-  _  <- word8 09
-  pu <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_PU
-  _  <- word8 09
-  sm <- maybeOption parse_SAM_V1_6_SAM_V1_6_Read_Group_SM
-  return SAM_V1_6_Read_Group { sam_v1_6_read_group_identifer                    = id
-                             , sam_v1_6_read_group_barcode_sequence             = bc
-                             , sam_v1_6_read_group_sequencing_center            = cn
-                             , sam_v1_6_read_group_description                  = ds
-                             , sam_v1_6_read_group_run_date                     = dt
-                             , sam_v1_6_read_group_flow_order                   = fo
-                             , sam_v1_6_read_group_key_sequence                 = ks
-                             , sam_v1_6_read_group_library                      = lb
-                             , sam_v1_6_read_group_programs                     = pg
-                             , sam_v1_6_read_group_predicted_median_insert_size = pi
-                             , sam_v1_6_read_group_platform                     = pl
-                             , sam_v1_6_read_group_platform_model               = pm
-                             , sam_v1_6_read_group_platform_unit                = pu
-                             , sam_v1_6_read_group_sample                       = sm
-                             }
+  -- This parser assumes that the
+  -- ID, BC, CN, DS, DT, FO, KS, LB, PG, PI, PL,
+  -- PM, PU and SM tags can appear in any order.
+  rg <- intercalateEffect (word8 09) $
+          SAM_V1_6_Read_Group
+            <$> toPermutation parse_SAM_V1_6_Read_Group_ID
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_BC)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_CN)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_DS)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_DT)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_FO)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_KS)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_LB)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_PG)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_PI)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_PL)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_PM)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_PU)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Read_Group_SM)
+  _ <- endOfLine
+  return rg 
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/CN.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/CN.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/CN.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/CN.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.CN ( -- * SAM_V1_6 parser - header section (Read group) - CN tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_CN
+                                                      parse_SAM_V1_6_Read_Group_CN
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the CN tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_CN :: Parser SAM_V1_6_Read_Group_Sequencing_Center 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_CN = do
+parse_SAM_V1_6_Read_Group_CN :: Parser SAM_V1_6_Read_Group_Sequencing_Center 
+parse_SAM_V1_6_Read_Group_CN = do
   _ <- do rgheadersequencingcentertagp <- DABL.takeTill (== 58)
           -- Parse CN tag of the header section.
           case (rgheadersequencingcentertagp =~ [re|[C][N]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Sequencing_Center_Incorrect_Format 
             True  -> -- CN tag is in the accepted format. 
-                     return rgheadersequencingcentertagp
+                     return ()
   _ <- word8 58
-  rgheadersequencingcentervalue <- DABL.takeTill (== 09)
+  rgheadersequencingcentervalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Sequencing_Center { sam_v1_6_read_group_sequencing_center_value = rgheadersequencingcentervalue
                                                }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/DS.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/DS.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/DS.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/DS.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.DS ( -- * SAM_V1_6 parser - header section (Read group) - DS tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_DS
+                                                      parse_SAM_V1_6_Read_Group_DS
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the DS tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_DS :: Parser SAM_V1_6_Read_Group_Description 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_DS = do
+parse_SAM_V1_6_Read_Group_DS :: Parser SAM_V1_6_Read_Group_Description 
+parse_SAM_V1_6_Read_Group_DS = do
   _ <- do rgheaderdescriptiontagp <- DABL.takeTill (== 58)
           -- Parse DS tag of the header section.
           case (rgheaderdescriptiontagp =~ [re|[D][S]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Description_Incorrect_Format 
             True  -> -- DS tag is in the accepted format. 
-                     return rgheaderdescriptiontagp
+                     return ()
   _ <- word8 58
-  rgheaderdescriptionvalue <- DABL.takeTill (== 09)
+  rgheaderdescriptionvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Description { sam_v1_6_read_group_description_value = rgheaderdescriptionvalue
                                          }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/DT.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/DT.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/DT.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/DT.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.DT ( -- * SAM_V1_6 parser - header section (Read group) - DT tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_DT
+                                                      parse_SAM_V1_6_Read_Group_DT
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the DT tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_DT :: Parser SAM_V1_6_Read_Group_Run_Date 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_DT = do
+parse_SAM_V1_6_Read_Group_DT :: Parser SAM_V1_6_Read_Group_Run_Date 
+parse_SAM_V1_6_Read_Group_DT = do
   _ <- do rgheaderrundatetagp <- DABL.takeTill (== 58)
           -- Parse DT tag of the header section.
           case (rgheaderrundatetagp =~ [re|[D][T]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Date_Run_Produced_Incorrect_Format
             True  -> -- DT tag is in the accepted format. 
-                     return rgheaderrundatetagp
+                     return ()
   _ <- word8 58
-  rgheaderrundatevalue <- DABL.takeTill (== 09)
+  rgheaderrundatevalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Run_Date { sam_v1_6_read_group_run_date_value = rgheaderrundatevalue
                                       }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/FO.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/FO.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/FO.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/FO.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,30 +40,31 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.FO ( -- * SAM_V1_6 parser - header section (Read group) - FO tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_FO
+                                                      parse_SAM_V1_6_Read_Group_FO
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the FO tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_FO :: Parser SAM_V1_6_Read_Group_Flow_Order 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_FO = do
+parse_SAM_V1_6_Read_Group_FO :: Parser SAM_V1_6_Read_Group_Flow_Order 
+parse_SAM_V1_6_Read_Group_FO = do
   _ <- do rgheaderflowordertagp <- DABL.takeTill (== 58)
           -- Parse FO tag of the header section.
           case (rgheaderflowordertagp =~ [re|[F][O]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Flow_Order_Incorrect_Format
             True  -> -- FO tag is in the accepted format. 
-                     return rgheaderflowordertagp
+                     return ()
   _ <- word8 58
-  rgheaderflowordervalue <- do rgheaderflowordervaluep <- DABL.takeTill (== 09)
+  rgheaderflowordervalue <- do rgheaderflowordervaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                -- Parse FO value of the header section.
-                               case (rgheaderflowordervaluep =~ [re|/\*|[ACMGRSVTWYHKDBN]+/|]) of
+                               case (rgheaderflowordervaluep =~ [re|\*|[ACMGRSVTWYHKDBN]+|]) of
                                  False -> fail $ show SAM_V1_6_Error_Read_Group_Flow_Order_Incorrect_Format
                                  True  -> -- FO value is in the accepted format.
                                           return rgheaderflowordervaluep
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/ID.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/ID.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/ID.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/ID.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.ID ( -- * SAM_V1_6 parser - header section (Read group) - ID tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_ID
+                                                      parse_SAM_V1_6_Read_Group_ID
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the ID tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_ID :: Parser SAM_V1_6_Read_Group_Identifier 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_ID = do
+parse_SAM_V1_6_Read_Group_ID :: Parser SAM_V1_6_Read_Group_Identifier 
+parse_SAM_V1_6_Read_Group_ID = do
   _ <- do rgheaderreadgroupidentifiertagp <- DABL.takeTill (== 58)
           -- Parse ID tag of the header section.
           case (rgheaderreadgroupidentifiertagp =~ [re|[I][D]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Read_Group_Identifier_Incorrect_Format
             True  -> -- ID tag is in the accepted format. 
-                     return rgheaderreadgroupidentifiertagp
+                     return ()
   _ <- word8 58
-  rgheaderreadgroupidentifiervalue <- DABL.takeTill (== 09)
+  rgheaderreadgroupidentifiervalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Identifier { sam_v1_6_read_group_identifier_value = rgheaderreadgroupidentifiervalue
                                         }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/KS.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/KS.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/KS.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/KS.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.KS ( -- * SAM_V1_6 parser - header section (Read group) - KS tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_KS
+                                                      parse_SAM_V1_6_Read_Group_KS
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the KS tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_KS :: Parser SAM_V1_6_Read_Group_Key_Sequence 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_KS = do
+parse_SAM_V1_6_Read_Group_KS :: Parser SAM_V1_6_Read_Group_Key_Sequence 
+parse_SAM_V1_6_Read_Group_KS = do
   _ <- do rgheaderkeysequencetagp <- DABL.takeTill (== 58)
           -- Parse KS tag of the header section.
           case (rgheaderkeysequencetagp =~ [re|[K][S]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Key_Sequence_Incorrect_Format
             True  -> -- KS tag is in the accepted format. 
-                     return rgheaderkeysequencetagp
+                     return ()
   _ <- word8 58
-  rgheaderkeysequencevalue <- DABL.takeTill (== 09)
+  rgheaderkeysequencevalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Key_Sequence { sam_v1_6_read_group_key_sequence_value = rgheaderkeysequencevalue
                                           }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/LB.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/LB.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/LB.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/LB.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.LB ( -- * SAM_V1_6 parser - header section (Read group) - LB tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_LB
+                                                      parse_SAM_V1_6_Read_Group_LB
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the LB tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_LB :: Parser SAM_V1_6_Read_Group_Library 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_LB = do
+parse_SAM_V1_6_Read_Group_LB :: Parser SAM_V1_6_Read_Group_Library 
+parse_SAM_V1_6_Read_Group_LB = do
   _ <- do rgheaderlibrarytagp <- DABL.takeTill (== 58)
           -- Parse LB tag of the header section.
           case (rgheaderlibrarytagp =~ [re|[L][B]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Library_Incorrect_Format
             True  -> -- LB tag is in the accepted format. 
-                     return rgheaderlibrarytagp
+                     return ()
   _ <- word8 58
-  rgheaderlibraryvalue <- DABL.takeTill (== 09)
+  rgheaderlibraryvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Library { sam_v1_6_read_group_library_value = rgheaderlibraryvalue
                                      }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PG.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PG.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PG.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PG.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.PG ( -- * SAM_V1_6 parser - header section (Read group) - PG tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_PG
+                                                      parse_SAM_V1_6_Read_Group_PG
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the PG tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PG :: Parser SAM_V1_6_Read_Group_Programs 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PG = do
+parse_SAM_V1_6_Read_Group_PG :: Parser SAM_V1_6_Read_Group_Programs 
+parse_SAM_V1_6_Read_Group_PG = do
   _ <- do rgheaderprogramstagp <- DABL.takeTill (== 58)
           -- Parse PG tag of the header section.
           case (rgheaderprogramstagp =~ [re|[P][G]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Programs_Incorrect_Format
             True  -> -- PG tag is in the accepted format. 
-                     return rgheaderprogramstagp
+                     return ()
   _ <- word8 58
-  rgheaderprogramsvalue <- DABL.takeTill (== 09)
+  rgheaderprogramsvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Programs { sam_v1_6_read_group_programs_value = rgheaderprogramsvalue
                                       }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PI.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PI.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PI.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PI.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.PI ( -- * SAM_V1_6 parser - header section (Read group) - PI tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_PI
+                                                      parse_SAM_V1_6_Read_Group_PI
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the PI tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PI :: Parser SAM_V1_6_Read_Group_Predicted_Median_Insert_Size 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PI = do
+parse_SAM_V1_6_Read_Group_PI :: Parser SAM_V1_6_Read_Group_Predicted_Median_Insert_Size 
+parse_SAM_V1_6_Read_Group_PI = do
   _ <- do rgheaderpredictedmedianinsertsizetagp <- DABL.takeTill (== 58)
           -- Parse PI tag of the header section.
           case (rgheaderpredictedmedianinsertsizetagp =~ [re|[P][I]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Predicted_Median_Insert_Size_Incorrect_Format
             True  -> -- PI tag is in the accepted format. 
-                     return rgheaderpredictedmedianinsertsizetagp
+                     return ()
   _ <- word8 58
-  rgheaderpredictedmedianinsertsizevalue <- DABL.takeTill (== 09)
+  rgheaderpredictedmedianinsertsizevalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Predicted_Median_Insert_Size { sam_v1_6_read_group_predicted_median_insert_size_value = rgheaderpredictedmedianinsertsizevalue
                                                           }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PL.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PL.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PL.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PL.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,28 +40,29 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.PL ( -- * SAM_V1_6 parser - header section (Read group) - PL tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_PL
+                                                      parse_SAM_V1_6_Read_Group_PL
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the PL tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PL :: Parser SAM_V1_6_Read_Group_Platform 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PL = do
+parse_SAM_V1_6_Read_Group_PL :: Parser SAM_V1_6_Read_Group_Platform 
+parse_SAM_V1_6_Read_Group_PL = do
   _ <- do rgheaderplatformtagp <- DABL.takeTill (== 58)
           -- Parse PL tag of the header section.
           case (rgheaderplatformtagp =~ [re|[P][L]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Platform_Incorrect_Format
             True  -> -- PL tag is in the accepted format. 
-                     return rgheaderplatformtagp
+                     return ()
   _ <- word8 58
-  rgheaderplatformvalue <- do rgheaderplatformvaluep <- DABL.takeTill (== 09)
+  rgheaderplatformvalue <- do rgheaderplatformvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                               -- Parse PL value of the header section.
                               case (rgheaderplatformvaluep =~ [re|[C][A][P][I][L][L][A][R][Y]|[D][N][B][S][E][Q]|[E][L][E][M][E][N][T]|[H][E][L][I][C][O][S]|[I][L][L][U][M][I][N][A]|[I][O][N][T][O][R][R][E][N][T]|[L][S][4][5][4]|[O][N][T]|[P][A][C][B][I][O]|[S][O][L][I][D]|[U][L][T][I][M][A]|]) of
                                 False -> fail $ show SAM_V1_6_Error_Read_Group_Platform_Incorrect_Format
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PM.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PM.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PM.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PM.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.PM ( -- * SAM_V1_6 parser - header section (Read group) - PM tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_PM
+                                                      parse_SAM_V1_6_Read_Group_PM
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the PM tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PM :: Parser SAM_V1_6_Read_Group_Platform_Model 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PM = do
+parse_SAM_V1_6_Read_Group_PM :: Parser SAM_V1_6_Read_Group_Platform_Model 
+parse_SAM_V1_6_Read_Group_PM = do
   _ <- do rgheaderplatformmodeltagp <- DABL.takeTill (== 58)
           -- Parse PM tag of the header section.
           case (rgheaderplatformmodeltagp =~ [re|[P][M]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Platform_Model_Incorrect_Format
             True  -> -- PM tag is in the accepted format. 
-                     return rgheaderplatformmodeltagp
+                     return ()
   _ <- word8 58
-  rgheaderplatformmodelvalue <- DABL.takeTill (== 09)
+  rgheaderplatformmodelvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Platform_Model { sam_v1_6_read_group_platform_model_value = rgheaderplatformmodelvalue
                                             }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PU.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PU.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PU.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/PU.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.PU ( -- * SAM_V1_6 parser - header section (Read group) - PU tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_PU
+                                                      parse_SAM_V1_6_Read_Group_PU
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the PU tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PU :: Parser SAM_V1_6_Read_Group_Platform_Unit 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_PU = do
+parse_SAM_V1_6_Read_Group_PU :: Parser SAM_V1_6_Read_Group_Platform_Unit 
+parse_SAM_V1_6_Read_Group_PU = do
   _ <- do rgheaderplatformunittagp <- DABL.takeTill (== 58)
           -- Parse PU tag of the header section.
           case (rgheaderplatformunittagp =~ [re|[P][U]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Platform_Unit_Incorrect_Format 
             True  -> -- PU tag is in the accepted format. 
-                     return rgheaderplatformunittagp
+                     return ()
   _ <- word8 58
-  rgheaderplatformunitvalue <- DABL.takeTill (== 09)
+  rgheaderplatformunitvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Platform_Unit { sam_v1_6_read_group_platform_unit_value = rgheaderplatformunitvalue
                                            }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/SM.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/SM.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/RG/SM.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/RG/SM.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.RG.SM ( -- * SAM_V1_6 parser - header section (Read group) - SM tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Read_Group_SM
+                                                      parse_SAM_V1_6_Read_Group_SM
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the SM tag of the @RG tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Read_Group_SM :: Parser SAM_V1_6_Read_Group_Sample 
-parse_SAM_V1_6_SAM_V1_6_Read_Group_SM = do
+parse_SAM_V1_6_Read_Group_SM :: Parser SAM_V1_6_Read_Group_Sample 
+parse_SAM_V1_6_Read_Group_SM = do
   _ <- do rgheadersampletagp <- DABL.takeTill (== 58)
           -- Parse SM tag of the header section.
           case (rgheadersampletagp =~ [re|[S][M]|]) of
             False -> fail $ show SAM_V1_6_Error_Read_Group_Sample_Incorrect_Format
             True  -> -- SM tag is in the accepted format. 
-                     return rgheadersampletagp
+                     return ()
   _ <- word8 58
-  rgheadersamplevalue <- DABL.takeTill (== 09)
+  rgheadersamplevalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Read_Group_Sample { sam_v1_6_read_group_sample_value = rgheadersamplevalue
                                     }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AH.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AH.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AH.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AH.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.AH ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - AH tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AH
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_AH
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the AH tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AH :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Alternative_Locus
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AH = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_AH :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Alternative_Locus
+parse_SAM_V1_6_Reference_Sequence_Dictionary_AH = do
   _ <- do sqheaderalternativelocustagp <- DABL.takeTill (== 58)
           -- Parse AH tag of the header section.
           case (sqheaderalternativelocustagp =~ [re|[A][H]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Alternative_Locus_Incorrect_Format
             True  -> -- AH tag is in the accepted format.
-                     return sqheaderalternativelocustagp
+                     return ()
   _ <- word8 58
-  sqheaderalternativelocusvalue <- DABL.takeTill (== 09) 
+  sqheaderalternativelocusvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Reference_Sequence_Dictionary_Alternative_Locus { sam_v1_6_reference_sequence_dictionary_alternative_locus_value = sqheaderalternativelocusvalue
                                                                   }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AN.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AN.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AN.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AN.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,30 +40,31 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.AN ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - AN tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AN
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_AN
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the AN tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AN :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Alternative_Reference_Sequence_Names
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AN = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_AN :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Alternative_Reference_Sequence_Names
+parse_SAM_V1_6_Reference_Sequence_Dictionary_AN = do
   _ <- do sqheaderalternativereferencesequencenamestagp <- DABL.takeTill (== 58)
           -- Parse AN tag of the header section.
           case (sqheaderalternativereferencesequencenamestagp =~ [re|[A][N]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Alternative_Reference_Sequence_Names_Incorrect_Format
             True  -> -- AN tag is in the accepted format.
-                     return sqheaderalternativereferencesequencenamestagp
+                     return ()
   _ <- word8 58
-  sqheaderalternativereferencesequencenamesvalue <- do sqheaderalternativereferencesequencenamesvaluep <- DABL.takeTill (== 09)
+  sqheaderalternativereferencesequencenamesvalue <- do sqheaderalternativereferencesequencenamesvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                                        -- Parse AN value of the header section.
-                                                       case (sqheaderalternativereferencesequencenamesvaluep =~ [re|[0-9A-Za-z!#$%&+./:;?@^_|~-][0-9A-Za-z!#$%&*+./:;=?@^_|~-]*(,[0-9A-Za-z!#$%&+./:;?@^_|~-][0-9A-Za-z!#$%&*+./:;=?@^_|~-]*)*|]) of
+                                                       case (sqheaderalternativereferencesequencenamesvaluep =~ [re|[0-9A-Za-z!#$%&+.:;?@^_|~-][0-9A-Za-z!#$%&*+.:;=?@^_|~-]*(,[0-9A-Za-z!#$%&+.:;?@^_|~-][0-9A-Za-z!#$%&*+.:;=?@^_|~-]*)*|]) of
                                                          False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Alternative_Reference_Sequence_Names_Invalid_Value
                                                          True  -> -- AN value is in the accepted format.
                                                                   return sqheaderalternativereferencesequencenamesvaluep
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AS.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AS.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AS.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/AS.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.AS ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - AS tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AS
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_AS
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the AS tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AS :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Genome_Assembly_Identifier
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AS = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_AS :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Genome_Assembly_Identifier
+parse_SAM_V1_6_Reference_Sequence_Dictionary_AS = do
   _ <- do sqheadergenomeassemblyidentifiertagp <- DABL.takeTill (== 58)
           -- Parse AS tag of the header section.
           case (sqheadergenomeassemblyidentifiertagp =~ [re|[A][S]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Genome_Assembly_Identifier_Incorrect_Format
             True  -> -- AS tag is in the accepted format.
-                     return sqheadergenomeassemblyidentifiertagp
+                     return ()
   _ <- word8 58
-  sqheadergenomeassemblyidentifiervalue <- DABL.takeTill (== 09)
+  sqheadergenomeassemblyidentifiervalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Reference_Sequence_Dictionary_Genome_Assembly_Identifier { sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier_value = sqheadergenomeassemblyidentifiervalue
                                                                            }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/Base.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/Base.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/Base.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/Base.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -57,14 +56,11 @@
 import Data.SAM.Version1_6.Read.Parser.Header.SQ.TP
 import Data.SAM.Version1_6.Read.Parser.Header.SQ.UR
 
+import Control.Applicative.Permutations           (intercalateEffect,toPermutation,toPermutationWithDefault)
+import Data.Attoparsec.ByteString.Char8  as DABC8 (endOfLine)
 import Data.Attoparsec.ByteString.Lazy   as DABL
 import Text.Regex.PCRE.Heavy
 
--- | Make a parser optional, return Nothing if there is no match.
-maybeOption :: Parser a
-            -> Parser (Maybe a)
-maybeOption p = option Nothing (Just <$> p)
-
 -- | @"SAM_V1_6_Reference_Sequence_Dictionary"@ parser.
 --
 -- Defines a parser for @SQ tag section of the SAM v1.6 file format.
@@ -77,38 +73,30 @@
                   case (sqheaderp =~ [re|[@][S][Q]|]) of
                     False -> fail $ show SAM_V1_6_Error_File_Level_Metadata_Tag_Incorrect_Format
                     True  -> -- @SQ tag is in the accepted format.
-                             return sqheaderp
+                             return ()
   _         <- word8 09
-  -- This parser assumes that the SN tag always appears first, followed by
-  -- the LN tag, followed by the AH, AN, AS, DS, M5,
-  -- SP, TP and UR tags if they exist, in that order.
-  sn <- parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_SN
-  _  <- word8 09
-  ln <- parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_LN
-  _  <- word8 09
-  ah <- maybeOption parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AH
-  _  <- word8 09
-  an <- maybeOption parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AN
-  _  <- word8 09
-  as <- maybeOption parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_AS
-  _  <- word8 09
-  ds <- maybeOption parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_DS
-  _  <- word8 09
-  m5 <- maybeOption parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_M5
-  _  <- word8 09
-  sp <- maybeOption parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_SP
-  _  <- word8 09
-  tp <- maybeOption parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_TP
-  _  <- word8 09
-  ur <- maybeOption parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_UR 
-  return SAM_V1_6_Reference_Sequence_Dictionary { sam_v1_6_reference_sequence_dictionary_reference_sequence_name                        = sn  
-                                                , sam_v1_6_reference_sequence_dictionary_reference_sequence_length                      = ln
-                                                , sam_v1_6_reference_sequence_dictionary_reference_alternative_locus                    = ah
-                                                , sam_v1_6_reference_sequence_dictionary_reference_alternative_reference_sequence_names = an
-                                                , sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier                     = as
-                                                , sam_v1_6_reference_sequence_dictionary_description                                    = ds
-                                                , sam_v1_6_reference_sequence_dictionary_md5_checksum                                   = m5
-                                                , sam_v1_6_reference_sequence_dictionary_species                                        = sp
-                                                , sam_v1_6_reference_sequence_dictionary_molecule_topology                              = tp
-                                                , sam_v1_6_reference_sequence_dictionary_uri                                            = ur
-                                                } 
+  -- This parser assumes that the
+  -- SN, LN, AH, AN, AS, DS, M5,
+  -- SP, TP and UR tags can appear in any order.
+  sq <- intercalateEffect (word8 09) $
+          SAM_V1_6_Reference_Sequence_Dictionary
+            <$> toPermutation parse_SAM_V1_6_Reference_Sequence_Dictionary_SN
+            <*> toPermutation parse_SAM_V1_6_Reference_Sequence_Dictionary_LN
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Reference_Sequence_Dictionary_AH)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Reference_Sequence_Dictionary_AN)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Reference_Sequence_Dictionary_AS)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Reference_Sequence_Dictionary_DS)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Reference_Sequence_Dictionary_M5)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Reference_Sequence_Dictionary_SP) 
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Reference_Sequence_Dictionary_TP)
+            <*> toPermutationWithDefault Nothing
+                                         (Just <$> parse_SAM_V1_6_Reference_Sequence_Dictionary_UR)
+  _ <- endOfLine
+  return sq
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/DS.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/DS.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/DS.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/DS.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.DS ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - DS tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_DS
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_DS
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the DS tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_DS :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Description
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_DS = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_DS :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Description
+parse_SAM_V1_6_Reference_Sequence_Dictionary_DS = do
   _ <- do sqheaderdescriptiontagp <- DABL.takeTill (== 58)
           -- Parse DS tag of the header section.
           case (sqheaderdescriptiontagp =~ [re|[D][S]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Description_Incorrect_Format 
             True  -> -- DS tag is in the accepted format.
-                     return sqheaderdescriptiontagp
+                     return ()
   _ <- word8 58
-  sqheaderdescriptionvalue <- DABL.takeTill (== 09)
+  sqheaderdescriptionvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Reference_Sequence_Dictionary_Description { sam_v1_6_reference_sequence_dictionary_description_value = sqheaderdescriptionvalue
                                                             }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/LN.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/LN.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/LN.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/LN.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,28 +40,29 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.LN ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - LN tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_LN
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_LN
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the LN tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_LN :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Length
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_LN = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_LN :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Length
+parse_SAM_V1_6_Reference_Sequence_Dictionary_LN = do
   _ <- do sqheadersequencelengthtagp <- DABL.takeTill (== 58)
           -- Parse LN tag of the header section.
           case (sqheadersequencelengthtagp =~ [re|[L][N]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Reference_Sequence_Length_Incorrect_Format
             True  -> -- LN tag is in the accepted format.
-                     return sqheadersequencelengthtagp
+                     return ()
   _ <- word8 58
-  sqheadersequencelengthvalue <- do sqheadersequencelengthvaluep <- DABL.takeTill (== 09)
+  sqheadersequencelengthvalue <- do sqheadersequencelengthvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                     -- Parse LN value of the header section.
                                     case (sqheadersequencelengthvaluep =~ [re|[0-9]*|]) of -- Make this regex actually check the range of [1,2^31 - 1]?
                                       False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Reference_Sequence_Length_Invalid_Value
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/M5.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/M5.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/M5.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/M5.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.M5 ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - M5 tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_M5
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_M5
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the M5 tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_M5 :: Parser SAM_V1_6_Reference_Sequence_Dictionary_MD5_Checksum
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_M5 = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_M5 :: Parser SAM_V1_6_Reference_Sequence_Dictionary_MD5_Checksum
+parse_SAM_V1_6_Reference_Sequence_Dictionary_M5 = do
   _ <- do sqheadermd5checksumtagp <- DABL.takeTill (== 58)
           -- Parse M5 tag of the header section.
           case (sqheadermd5checksumtagp =~ [re|[M][5]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_MD5_Checksum_Incorrect_Format 
             True  -> -- M5 tag is in the accepted format.
-                     return sqheadermd5checksumtagp
+                     return ()
   _ <- word8 58
-  sqheadermd5checksumvalue <- DABL.takeTill (== 09)
+  sqheadermd5checksumvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Reference_Sequence_Dictionary_MD5_Checksum { sam_v1_6_reference_sequence_dictionary_md5_checksum_value = sqheadermd5checksumvalue
                                                              }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/SN.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/SN.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/SN.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/SN.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,32 +40,33 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.SN ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - SN tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_SN
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_SN
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the SN tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_SN :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Name
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_SN = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_SN :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Name
+parse_SAM_V1_6_Reference_Sequence_Dictionary_SN = do
   _ <- do sqheadersequencenametagp <- DABL.takeTill (== 58)
           -- Parse SN tag of the header section.
           case (sqheadersequencenametagp =~ [re|[S][N]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Reference_Sequence_Name_Incorrect_Format
             True  -> -- SN tag is in the accepted format. 
-                     return sqheadersequencenametagp
+                     return ()
   _ <- word8 58
-  sqheadersequencenamevalue <- do sqheadersequencenamevaluep <- DABL.takeTill (== 09)
+  sqheadersequencenamevalue <- do sqheadersequencenamevaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                   -- Parse SN value of the header section.
                                   case (sqheadersequencenamevaluep =~ [re|[0-9A-Za-z!#$%&+./:;?@^_|~-][0-9A-Za-z!#$%&*+./:;=?@^_|~-]*|]) of
                                     False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Reference_Sequence_Name_Invalid_Value
                                     True  -> -- SN value is in the accepted format.
-                                             return sqheadersequencenamevaluep  
+                                             return sqheadersequencenamevaluep
   return SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Name { sam_v1_6_reference_sequence_dictionary_reference_sequence_name_value = sqheadersequencenamevalue
                                                                         }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/SP.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/SP.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/SP.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/SP.hs
@@ -41,27 +41,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.SP ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - SP tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_SP
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_SP
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the SP tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_SP :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Species
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_SP = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_SP :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Species
+parse_SAM_V1_6_Reference_Sequence_Dictionary_SP = do
   _ <- do sqheaderspeciestagp <- DABL.takeTill (== 58)
           -- Parse SP tag of the header section.
           case (sqheaderspeciestagp =~ [re|[S][P]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Species_Incorrect_Format
             True  -> -- SP tag is in the accepted format.
-                     return sqheaderspeciestagp
+                     return ()
   _ <- word8 58
-  sqheaderspeciesvalue <- DABL.takeTill (== 09)
+  sqheaderspeciesvalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Reference_Sequence_Dictionary_Species { sam_v1_6_reference_sequence_dictionary_species_value = sqheaderspeciesvalue
                                                         }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/TP.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/TP.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/TP.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/TP.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,32 +40,33 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.TP ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - TP tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_TP
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_TP
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the TP tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_TP :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Molecule_Topology
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_TP = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_TP :: Parser SAM_V1_6_Reference_Sequence_Dictionary_Molecule_Topology
+parse_SAM_V1_6_Reference_Sequence_Dictionary_TP = do
   _ <- do sqheadermoleculetopologytagp <- DABL.takeTill (== 58)
           -- Parse TP tag of the header section.
           case (sqheadermoleculetopologytagp =~ [re|[T][P]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Molecule_Topology_Incorrect_Format
             True  -> -- TP tag is in the accepted format. 
-                     return sqheadermoleculetopologytagp
+                     return ()
   _ <- word8 58
-  sqheadermoleculetopologyvalue <- do sqheadermoleculetopologyvaluep <- DABL.takeTill (== 09)
+  sqheadermoleculetopologyvalue <- do sqheadermoleculetopologyvaluep <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
                                       -- Parse TP value of the header section.
                                       case (sqheadermoleculetopologyvaluep =~ [re|[l][i][n][e][a][r]|[c][i][r][c][u][l][a][r]|]) of
                                         False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_Molecule_Topology_Invalid_Value
                                         True  -> -- TP value is in the accepted format.
-                                                 return sqheadermoleculetopologyvaluep  
+                                                 return sqheadermoleculetopologyvaluep
   return SAM_V1_6_Reference_Sequence_Dictionary_Molecule_Topology { sam_v1_6_reference_sequence_dictionary_molecule_topology_value = sqheadermoleculetopologyvalue
                                                                   }
diff --git a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/UR.hs b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/UR.hs
--- a/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/UR.hs
+++ b/src/Data/SAM/Version1_6/Read/Parser/Header/SQ/UR.hs
@@ -9,7 +9,6 @@
 {-# LANGUAGE PackageImports        #-}
 {-# LANGUAGE RecordWildCards       #-}
 {-# LANGUAGE ScopedTypeVariables   #-}
-{-# LANGUAGE TemplateHaskell       #-}
 {-# LANGUAGE TypeFamilies          #-}
 {-# LANGUAGE QuasiQuotes           #-}
 
@@ -41,27 +40,28 @@
 -- This library enables the decoding/encoding of SAM, BAM and CRAM file formats.
 
 module Data.SAM.Version1_6.Read.Parser.Header.SQ.UR ( -- * SAM_V1_6 parser - header section (Reference sequence dictionary) - UR tag
-                                                      parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_UR
+                                                      parse_SAM_V1_6_Reference_Sequence_Dictionary_UR
                                                     ) where
 
 import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Error
 
-import           Data.Attoparsec.ByteString.Lazy   as DABL
-import           Text.Regex.PCRE.Heavy
+import Data.Attoparsec.ByteString.Char8 (isEndOfLine)
+import Data.Attoparsec.ByteString.Lazy   as DABL
+import Text.Regex.PCRE.Heavy
 
 -- | Defines a parser for the UR tag of the @SQ tag section of the SAM v1.6 file format.
 --
 -- See the [SAM v1.6](http://samtools.github.io/hts-specs/SAMv1.pdf) specification documentation.
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_UR :: Parser SAM_V1_6_Reference_Sequence_Dictionary_URI
-parse_SAM_V1_6_SAM_V1_6_Reference_Sequence_Dictionary_UR = do
+parse_SAM_V1_6_Reference_Sequence_Dictionary_UR :: Parser SAM_V1_6_Reference_Sequence_Dictionary_URI
+parse_SAM_V1_6_Reference_Sequence_Dictionary_UR = do
   _ <- do sqheaderuritagp <- DABL.takeTill (== 58)
           -- Parse UR tag of the header section.
           case (sqheaderuritagp =~ [re|[U][R]|]) of
             False -> fail $ show SAM_V1_6_Error_Reference_Sequence_Dictionary_URI_Incorrect_Format
             True  -> -- UR tag is in the accepted format.
-                     return sqheaderuritagp
+                     return ()
   _ <- word8 58
-  sqheaderurivalue <- DABL.takeTill (== 09)
+  sqheaderurivalue <- DABL.takeTill (\x -> x == 09 || isEndOfLine x)
   return SAM_V1_6_Reference_Sequence_Dictionary_URI { sam_v1_6_reference_sequence_dictionary_uri_value = sqheaderurivalue
                                                     }
diff --git a/test/Main.hs b/test/Main.hs
--- a/test/Main.hs
+++ b/test/Main.hs
@@ -1,14 +1,65 @@
 module Main (main) where
 
+import Data.SAM.Version1_6.Base
+import Data.SAM.Version1_6.Alignment
+import Data.SAM.Version1_6.Alignment.BOPT
+import Data.SAM.Version1_6.Header
 import Data.SAM.Version1_6.Read.Base
 
+import Data.Sequence (fromList)
+import Data.String (fromString)
 import Test.Hspec
 
 main :: IO ()
-main = do --hspec $ do
- -- describe "Data.SAM.Version1_6.Read.Base" $ do
- --   describe "readSAM_V1_6" $ do
- --     describe "toy1.sam" $ do
- --       it "Ensures that readSAM_V1_6 can read and parse: toy1.sam" $ do
- toy1sam <- readSAM_V1_6 "test/examples/toy4.sam"
- print toy1sam 
+main = hspec $ do
+  describe "Data.SAM.Version1_6.Read.Base" $ do
+    describe "readSAM_V1_6" $ do
+      describe "toy5.sam" $ do
+        it "Ensures that readSAM_V1_6 can read and parse a SAM file with only alignment fields." $ do
+          readSAM_V1_6 "test/examples/toy5.sam" `shouldReturn` toy5sam
+      describe "toy4.sam" $ do
+        it "Ensures that readSAM_V1_6 can read and parse a SAM file with an optional alignment field." $ do
+          readSAM_V1_6 "test/examples/toy4.sam" `shouldReturn` toy4sam
+      describe "toy2.sam" $ do
+        it "Ensures that readSAM_V1_6 can read and parse a SAM file with file-level metadata (@HD) and reference sequence dictionary (@SQ) optional header fields." $ do
+          readSAM_V1_6 "test/examples/toy2.sam" `shouldReturn` toy2sam
+      describe "toy1.sam" $ do
+        it "Ensures that readSAM_V1_6 can read and parse a SAM file with multiple reference sequence dictionary (@SQ) optional header fields." $ do
+          readSAM_V1_6 "test/examples/toy1.sam" `shouldReturn` toy1sam
+  where
+    toy1sam = SAM_V1_6 { sam_v1_6_file_level_metadata = Nothing
+                       , sam_v1_6_reference_sequence_dictionary = Just (fromList [SAM_V1_6_Reference_Sequence_Dictionary { sam_v1_6_reference_sequence_dictionary_reference_sequence_name = SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Name { sam_v1_6_reference_sequence_dictionary_reference_sequence_name_value = fromString "ref" } , sam_v1_6_reference_sequence_dictionary_reference_sequence_length = SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Length { sam_v1_6_reference_sequence_dictionary_reference_sequence_length_value = fromString "45" } , sam_v1_6_reference_sequence_dictionary_reference_alternative_locus = Nothing , sam_v1_6_reference_sequence_dictionary_reference_alternative_reference_sequence_names = Nothing , sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier = Nothing , sam_v1_6_reference_sequence_dictionary_description = Nothing , sam_v1_6_reference_sequence_dictionary_md5_checksum = Nothing , sam_v1_6_reference_sequence_dictionary_species = Nothing , sam_v1_6_reference_sequence_dictionary_molecule_topology = Nothing , sam_v1_6_reference_sequence_dictionary_uri = Nothing },SAM_V1_6_Reference_Sequence_Dictionary { sam_v1_6_reference_sequence_dictionary_reference_sequence_name = SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Name { sam_v1_6_reference_sequence_dictionary_reference_sequence_name_value = fromString "ref2" } , sam_v1_6_reference_sequence_dictionary_reference_sequence_length = SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Length { sam_v1_6_reference_sequence_dictionary_reference_sequence_length_value = fromString "40" } , sam_v1_6_reference_sequence_dictionary_reference_alternative_locus = Nothing , sam_v1_6_reference_sequence_dictionary_reference_alternative_reference_sequence_names = Nothing , sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier = Nothing , sam_v1_6_reference_sequence_dictionary_description = Nothing , sam_v1_6_reference_sequence_dictionary_md5_checksum = Nothing , sam_v1_6_reference_sequence_dictionary_species = Nothing , sam_v1_6_reference_sequence_dictionary_molecule_topology = Nothing , sam_v1_6_reference_sequence_dictionary_uri = Nothing }])
+                       , sam_v1_6_read_group = Nothing
+                       , sam_v1_6_program = Nothing
+                       , sam_v1_6_one_line_comment = Nothing
+                       , sam_v1_6_alignment = fromList [ SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r001" , sam_v1_6_alignment_flag = 163 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 7 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "8M4I4M1D3M" , sam_v1_6_alignment_rnext = fromString "=" , sam_v1_6_alignment_pnext = 37 , sam_v1_6_alignment_tlen = 39 , sam_v1_6_alignment_seq = fromString "TTAGATAAAGAGGATACTG" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Just SAM_V1_6_Alignment_BOPT { sam_v1_6_alignment_bopt_int8 = Nothing , sam_v1_6_alignment_bopt_word8 = Nothing , sam_v1_6_alignment_bopt_int16 = Nothing , sam_v1_6_alignment_bopt_word16 = Just SAM_V1_6_Alignment_BOPT_Word16 { sam_v1_6_alignment_bopt_word16_tag  = fromList [88,88] , sam_v1_6_alignment_bopt_word16_type = 83 , sam_v1_6_alignment_bopt_word16_value = fromList [49,50,53,54,49,44,50,44,50,48,44,49,49,50] } , sam_v1_6_alignment_bopt_int32 = Nothing , sam_v1_6_alignment_bopt_word32 = Nothing , sam_v1_6_alignment_bopt_float = Nothing } },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r002" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 9 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "1S2I6M1P1I1P1I4M2I" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "AAAAGATAAGGGATAAA" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r003" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 9 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "5H6M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "AGCTAA" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r004" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 16 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "6M14N1I5M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ATAGCTCTCAGC" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r003" , sam_v1_6_alignment_flag = 16 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 29 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "6H5M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "TAGGC" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r001" , sam_v1_6_alignment_flag = 83 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 37 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "9M" , sam_v1_6_alignment_rnext = fromString "=" , sam_v1_6_alignment_pnext = 7 , sam_v1_6_alignment_tlen = -39 , sam_v1_6_alignment_seq = fromString "CAGCGCCAT" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x1" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 1 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "20M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "aggttttataaaacaaataa" , sam_v1_6_alignment_qual = fromString "????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x2" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 2 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "21M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ggttttataaaacaaataatt" , sam_v1_6_alignment_qual = fromString "?????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x3" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 6 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "9M4I13M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ttataaaacAAATaattaagtctaca" , sam_v1_6_alignment_qual = fromString "??????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x4" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 10 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "25M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "CaaaTaattaagtctacagagcaac" , sam_v1_6_alignment_qual = fromString "?????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x5" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 12 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "24M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "aaTaattaagtctacagagcaact" , sam_v1_6_alignment_qual = fromString "????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x6" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 14 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "23M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "Taattaagtctacagagcaacta" , sam_v1_6_alignment_qual = fromString "???????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing
+                                                                            }
+                                                       ]
+                       }
+    toy2sam = SAM_V1_6 { sam_v1_6_file_level_metadata = Just SAM_V1_6_File_Level_Metadata { sam_v1_6_file_level_metadata_format_version = SAM_V1_6_File_Level_Metadata_Format_Version { sam_v1_6_file_level_metadata_format_version_value = fromString "1.6" } , sam_v1_6_file_level_metadata_sorting_order = Just SAM_V1_6_File_Level_Metadata_Sorting_Order { sam_v1_6_file_level_metadata_sorting_order_value = fromString "coordinate" } , sam_v1_6_file_level_metadata_alignment_grouping = Nothing , sam_v1_6_file_level_metadata_subsorting_order = Nothing }
+                       , sam_v1_6_reference_sequence_dictionary = Just (fromList [SAM_V1_6_Reference_Sequence_Dictionary { sam_v1_6_reference_sequence_dictionary_reference_sequence_name = SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Name { sam_v1_6_reference_sequence_dictionary_reference_sequence_name_value = fromString "ref" } , sam_v1_6_reference_sequence_dictionary_reference_sequence_length = SAM_V1_6_Reference_Sequence_Dictionary_Reference_Sequence_Length { sam_v1_6_reference_sequence_dictionary_reference_sequence_length_value = fromString "45" } , sam_v1_6_reference_sequence_dictionary_reference_alternative_locus = Nothing , sam_v1_6_reference_sequence_dictionary_reference_alternative_reference_sequence_names = Nothing , sam_v1_6_reference_sequence_dictionary_genome_assembly_identifier = Nothing , sam_v1_6_reference_sequence_dictionary_description = Nothing , sam_v1_6_reference_sequence_dictionary_md5_checksum = Nothing , sam_v1_6_reference_sequence_dictionary_species = Nothing , sam_v1_6_reference_sequence_dictionary_molecule_topology = Nothing , sam_v1_6_reference_sequence_dictionary_uri = Nothing }])
+                       , sam_v1_6_read_group = Nothing
+                       , sam_v1_6_program = Nothing
+                       , sam_v1_6_one_line_comment = Nothing
+                       , sam_v1_6_alignment = fromList [ SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r001" , sam_v1_6_alignment_flag = 99 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 7 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "8M2I4M1D3M" , sam_v1_6_alignment_rnext = fromString "=" , sam_v1_6_alignment_pnext = 37 , sam_v1_6_alignment_tlen = 39 , sam_v1_6_alignment_seq = fromString "TTAGATAAAGGATACTG" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r002" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 9 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "3S6M1P1I4M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "AAAAGATAAGGATA" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r003" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 9 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "5S6M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "GCCTAAGCTAA" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Just (fromString "ref,29,-,6H5M,17,0;") , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r004" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 16 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "6M14N5M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ATAGCTTCAGC" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r003" , sam_v1_6_alignment_flag = 2064 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 29 , sam_v1_6_alignment_mapq = 17 , sam_v1_6_alignment_cigar = fromString "6H5M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "TAGGC" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Just (fromString "ref,9,+,5S6M,30,1;") , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r001" , sam_v1_6_alignment_flag = 147 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 37 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "9M" , sam_v1_6_alignment_rnext = fromString "=" , sam_v1_6_alignment_pnext = 7 , sam_v1_6_alignment_tlen = -39 , sam_v1_6_alignment_seq = fromString "CAGCGGCAT" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Just 1 , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing
+                                                                            }
+                                                       ]
+                       }
+    toy4sam = SAM_V1_6 { sam_v1_6_file_level_metadata = Nothing
+                       , sam_v1_6_reference_sequence_dictionary = Nothing
+                       , sam_v1_6_read_group = Nothing
+                       , sam_v1_6_program = Nothing
+                       , sam_v1_6_one_line_comment = Nothing
+                       , sam_v1_6_alignment = fromList [ SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r001" , sam_v1_6_alignment_flag = 163 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 7 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "8M4I4M1D3M" , sam_v1_6_alignment_rnext = fromString "=" , sam_v1_6_alignment_pnext = 37 , sam_v1_6_alignment_tlen = 39 , sam_v1_6_alignment_seq = fromString "TTAGATAAAGAGGATACTG" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Just SAM_V1_6_Alignment_BOPT { sam_v1_6_alignment_bopt_int8 = Nothing , sam_v1_6_alignment_bopt_word8 = Nothing , sam_v1_6_alignment_bopt_int16 = Nothing , sam_v1_6_alignment_bopt_word16 = Just SAM_V1_6_Alignment_BOPT_Word16 { sam_v1_6_alignment_bopt_word16_tag  = fromList [88,88] , sam_v1_6_alignment_bopt_word16_type = 83 , sam_v1_6_alignment_bopt_word16_value = fromList [49,50,53,54,49,44,50,44,50,48,44,49,49,50] } , sam_v1_6_alignment_bopt_int32 = Nothing , sam_v1_6_alignment_bopt_word32 = Nothing , sam_v1_6_alignment_bopt_float = Nothing } },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r002" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 9 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "1S2I6M1P1I1P1I4M2I" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "AAAAGATAAGGGATAAA" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r003" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 9 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "5H6M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "AGCTAA" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r004" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 16 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "6M14N1I5M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ATAGCTCTCAGC" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r003" , sam_v1_6_alignment_flag = 16 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 29 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "6H5M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "TAGGC" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r001" , sam_v1_6_alignment_flag = 83 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 37 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "9M" , sam_v1_6_alignment_rnext = fromString "=" , sam_v1_6_alignment_pnext = 7 , sam_v1_6_alignment_tlen = -39 , sam_v1_6_alignment_seq = fromString "CAGCGCCAT" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x1" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 1 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "20M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "aggttttataaaacaaataa" , sam_v1_6_alignment_qual = fromString "????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x2" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 2 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "21M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ggttttataaaacaaataatt" , sam_v1_6_alignment_qual = fromString "?????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x3" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 6 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "9M4I13M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ttataaaacAAATaattaagtctaca" , sam_v1_6_alignment_qual = fromString "??????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x4" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 10 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "25M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "CaaaTaattaagtctacagagcaac" , sam_v1_6_alignment_qual = fromString "?????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x5" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 12 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "24M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "aaTaattaagtctacagagcaact" , sam_v1_6_alignment_qual = fromString "????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x6" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 14 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "23M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "Taattaagtctacagagcaacta" , sam_v1_6_alignment_qual = fromString "???????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing
+                                                                            }
+                                                       ]
+                       }
+    toy5sam = SAM_V1_6 { sam_v1_6_file_level_metadata = Nothing
+                       , sam_v1_6_reference_sequence_dictionary = Nothing
+                       , sam_v1_6_read_group = Nothing
+                       , sam_v1_6_program = Nothing
+                       , sam_v1_6_one_line_comment = Nothing
+                       , sam_v1_6_alignment = fromList [ SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r001" , sam_v1_6_alignment_flag = 163 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 7 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "8M4I4M1D3M" , sam_v1_6_alignment_rnext = fromString "=" , sam_v1_6_alignment_pnext = 37 , sam_v1_6_alignment_tlen = 39 , sam_v1_6_alignment_seq = fromString "TTAGATAAAGAGGATACTG" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r002" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 9 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "1S2I6M1P1I1P1I4M2I" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "AAAAGATAAGGGATAAA" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r003" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 9 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "5H6M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "AGCTAA" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r004" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 16 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "6M14N1I5M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ATAGCTCTCAGC" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r003" , sam_v1_6_alignment_flag = 16 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 29 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "6H5M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "TAGGC" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "r001" , sam_v1_6_alignment_flag = 83 , sam_v1_6_alignment_rname = fromString "ref" , sam_v1_6_alignment_pos = 37 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "9M" , sam_v1_6_alignment_rnext = fromString "=" , sam_v1_6_alignment_pnext = 7 , sam_v1_6_alignment_tlen = -39 , sam_v1_6_alignment_seq = fromString "CAGCGCCAT" , sam_v1_6_alignment_qual = fromString "*" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x1" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 1 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "20M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "aggttttataaaacaaataa" , sam_v1_6_alignment_qual = fromString "????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x2" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 2 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "21M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ggttttataaaacaaataatt" , sam_v1_6_alignment_qual = fromString "?????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x3" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 6 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "9M4I13M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "ttataaaacAAATaattaagtctaca" , sam_v1_6_alignment_qual = fromString "??????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x4" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 10 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "25M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "CaaaTaattaagtctacagagcaac" , sam_v1_6_alignment_qual = fromString "?????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x5" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 12 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "24M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "aaTaattaagtctacagagcaact" , sam_v1_6_alignment_qual = fromString "????????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing },SAM_V1_6_Alignment { sam_v1_6_alignment_qname = fromString "x6" , sam_v1_6_alignment_flag = 0 , sam_v1_6_alignment_rname = fromString "ref2" , sam_v1_6_alignment_pos = 14 , sam_v1_6_alignment_mapq = 30 , sam_v1_6_alignment_cigar = fromString "23M" , sam_v1_6_alignment_rnext = fromString "*" , sam_v1_6_alignment_pnext = 0 , sam_v1_6_alignment_tlen = 0 , sam_v1_6_alignment_seq = fromString "Taattaagtctacagagcaacta" , sam_v1_6_alignment_qual = fromString "???????????????????????" , sam_v1_6_alignment_aopt = Nothing , sam_v1_6_alignment_iopt = Nothing , sam_v1_6_alignment_fopt = Nothing , sam_v1_6_alignment_zopt = Nothing , sam_v1_6_alignment_hopt = Nothing , sam_v1_6_alignment_bopt = Nothing
+                                                                            }
+                                                       ]
+                       }
