diff --git a/src/bamToBed/bamToBed.cpp b/src/bamToBed/bamToBed.cpp
index b825c524cbdc643ac4c9a725ab9b73d54f03a822..4a4c56c662a5d953191698534e74185808326baf 100644
--- a/src/bamToBed/bamToBed.cpp
+++ b/src/bamToBed/bamToBed.cpp
@@ -267,20 +267,18 @@ void ConvertBamToBedpe(const string &bamFile, const bool &useEditDistance) {
     // rip through the BAM file and convert each mapped entry to BEDPE
     BamAlignment bam1, bam2;
     while (reader.GetNextAlignment(bam1)) {
-        // the alignment must be paired
-        if (bam1.IsPaired() == true) {
-            // grab the second alignment for the pair.
-            reader.GetNextAlignment(bam2);
-
-            // require that the alignments are from the same query
-            if (bam1.Name == bam2.Name) {
-                PrintBedPE(bam1, bam2, refs, useEditDistance);
-            }
-            else {
-                cerr << "*****ERROR: -bedpe requires BAM to be sorted/grouped by query name. " << endl;
-                exit(1);
+        
+        reader.GetNextAlignment(bam2);        
+        if (bam1.Name != bam2.Name) {
+            while (bam1.Name != bam2.Name)
+            {
+                bam1 = bam2;
+                reader.GetNextAlignment(bam2);
             }
         }
+        else if (bam1.IsPaired() == true) {
+            PrintBedPE(bam1, bam2, refs, useEditDistance);
+        }
     }
     reader.Close();
 }