diff --git a/src/utils/Contexts/ContextBase.cpp b/src/utils/Contexts/ContextBase.cpp
index 051050f78d8611019c9da6f174547c0490d7e977..19f855e31cc20291e99f54da38783f42876add84 100644
--- a/src/utils/Contexts/ContextBase.cpp
+++ b/src/utils/Contexts/ContextBase.cpp
@@ -65,7 +65,6 @@ ContextBase::ContextBase()
 {
 	_programNames["intersect"] = INTERSECT;
 	_programNames["sample"] = SAMPLE;
-	_programNames["spacing"] = SPACING;
 	_programNames["map"] = MAP;
 	_programNames["merge"] = MERGE;
 
@@ -220,12 +219,12 @@ bool ContextBase::isValidState()
 	}
 	if (hasColumnOpsMethods()) {
 
-		// TBD: Adjust column ops for multiple databases.
-		// For now, use last file.
-		FileRecordMgr *dbFile = getFile(getNumInputFiles()-1);
-		_keyListOps->setDBfileType(dbFile->getFileType());
-		if (!_keyListOps->isValidColumnOps(dbFile)) {
-			return false;
+		for (int i=0; i < (int)_dbFileIdxs.size(); i++) {
+			FileRecordMgr *dbFile = getFile(_dbFileIdxs[i]);
+			_keyListOps->setDBfileType(dbFile->getFileType());
+			if (!_keyListOps->isValidColumnOps(dbFile)) {
+				return false;
+			}
 		}
 		//if user specified a precision, pass it to
 		//keyList ops
@@ -521,6 +520,7 @@ bool ContextBase::handle_null()
 bool ContextBase::handle_delim()
 {
 	if (!hasColumnOpsMethods()) {
+		_errorMsg = "\n***** ERROR: Can't set delimiter for tools without column operations. Exiting. *****";
 		return false;
 	}
     if ((_i+1) < _argc) {
diff --git a/src/utils/NewChromsweep/CloseSweep.h b/src/utils/NewChromsweep/CloseSweep.h
index f4708684c29929690c0c76c5b9b32656645ae6eb..10ece3eb17fb5836e9e5647131a713dff5ccaa45 100644
--- a/src/utils/NewChromsweep/CloseSweep.h
+++ b/src/utils/NewChromsweep/CloseSweep.h
@@ -27,7 +27,18 @@ public:
 class DistanceTupleSortAscFunctor {
 public:
 	bool operator()(const distanceTuple & d1, const distanceTuple & d2) const {
-		return ((d1._dist < d2._dist) ? true : (d1._dist == d2._dist ? (d1._isNeg && !d2._isNeg) : false)) ; }
+//		return ((d1._dist < d2._dist) ? true : (d1._dist == d2._dist ? (d1._rec->lessThan(d2._rec)) :  false)); }
+
+		return (d1._dist < d2._dist ? true : (d1._dist == d2._dist ? d1._rec->lessThan(d2._rec) : false));
+//		if (d1._dist < d2._dist) {
+//			return true;
+//		} else if (d1._dist == d2._dist) {
+//			if () {
+//				return true;
+//			}
+//		}
+//		return false;
+	}
 };
 
 
diff --git a/src/utils/RecordOutputMgr/RecordOutputMgr.cpp b/src/utils/RecordOutputMgr/RecordOutputMgr.cpp
index a557b42c9d24e7bade27b5dda9501b14882d375b..1d58ef59702a8a2fc6dbd2ef23bf4a59f0c4d589 100644
--- a/src/utils/RecordOutputMgr/RecordOutputMgr.cpp
+++ b/src/utils/RecordOutputMgr/RecordOutputMgr.cpp
@@ -218,6 +218,8 @@ void RecordOutputMgr::printRecord(RecordKeyVector &keyList, RecordKeyVector *blo
 					if (printKeyAndTerminate(keyList)) {
 
 						_currBamBlockList = NULL;
+						const_cast<Record *>(keyList.getKey())->adjustZeroLength();
+
 						return;
 					}
 					tab();
@@ -231,6 +233,7 @@ void RecordOutputMgr::printRecord(RecordKeyVector &keyList, RecordKeyVector *blo
 					if (printKeyAndTerminate(keyList)) {
 						_currBamBlockList = NULL;
 
+						const_cast<Record *>(keyList.getKey())->adjustZeroLength();
 						return;
 					}
 					tab();
@@ -245,6 +248,7 @@ void RecordOutputMgr::printRecord(RecordKeyVector &keyList, RecordKeyVector *blo
 				if (printBamRecord(keyList, true) == BAM_AS_BAM) {
 					_currBamBlockList = NULL;
 
+					const_cast<Record *>(keyList.getKey())->adjustZeroLength();
 					return;
 				}
 				int hitIdx = 0;
@@ -261,24 +265,12 @@ void RecordOutputMgr::printRecord(RecordKeyVector &keyList, RecordKeyVector *blo
 		if (!printKeyAndTerminate(keyList)) {
 			newline();
 		}
-		_currBamBlockList = NULL;
-
-		return;
-	} else if (_context->getProgram() == ContextBase::MAP) {
-		printKeyAndTerminate(keyList);
-		_currBamBlockList = NULL;
-
-		return;
-	} else if (_context->getProgram() == ContextBase::MERGE) {
+	} else if (_context->getProgram() == ContextBase::MAP || _context->getProgram() == ContextBase::MERGE) {
 		printKeyAndTerminate(keyList);
-		_currBamBlockList = NULL;
-
-		return;
-	} else if (_context->getProgram() == ContextBase::SPACING) {
-		keyList.getKey()->print(_outBuf);
-		_currBamBlockList = NULL;
-		return;
 	}
+	_currBamBlockList = NULL;
+	const_cast<Record *>(keyList.getKey())->adjustZeroLength();
+
 }
 
 void RecordOutputMgr::checkForHeader() {
@@ -397,7 +389,7 @@ void RecordOutputMgr::reportOverlapDetail(const Record *keyRecord, const Record
 		newline();
 		if (needsFlush()) flush();
 	}
-	const_cast<Record *>(keyRecord)->adjustZeroLength();
+	const_cast<Record *>(hitRecord)->adjustZeroLength();
 }
 
 void RecordOutputMgr::reportOverlapSummary(RecordKeyVector &keyList)
diff --git a/test/closest/kclosest/test-kclosest.sh b/test/closest/kclosest/test-kclosest.sh
index 10cf7f525443a332a790c94b97c2cc3fa3153daa..7a99886e7a4982a2a482314c8f3d2be4f1decc05 100644
--- a/test/closest/kclosest/test-kclosest.sh
+++ b/test/closest/kclosest/test-kclosest.sh
@@ -471,21 +471,22 @@ rm obs exp
 # Test multiple databases and mdb = all mode
 ###########################################################
 
+
 echo "    kclosest.t30...\c"
 echo \
-"chr1	100	110	q2.1	20	+	1	chr1	98	108	2.2	20	+	0
-chr1	100	110	q2.1	20	+	1	chr1	105	115	2.3	20	+	0
+"chr1	100	110	q2.1	20	+	2	chr1	90	105	3.7	20	+	0
 chr1	100	110	q2.1	20	+	1	chr1	95	105	2.1	20	+	0
 chr1	100	110	q2.1	20	+	2	chr1	95	110	3.8	20	-	0
-chr1	100	110	q2.1	20	+	2	chr1	90	105	3.7	20	+	0
+chr1	100	110	q2.1	20	+	1	chr1	98	108	2.2	20	+	0
+chr1	100	110	q2.1	20	+	1	chr1	105	115	2.3	20	+	0
 chr1	100	110	q2.1	20	+	2	chr1	110	115	3.9	20	+	1
 chr1	100	110	q2.1	20	+	1	chr1	120	130	2.4	20	+	11
 chr1	100	110	q2.1	20	+	2	chr1	120	130	3.10	20	-	11
 chr1	100	110	q2.1	20	+	2	chr1	70	80	3.6	20	+	-21
 chr1	100	110	q2.1	20	+	2	chr1	75	80	3.65	20	+	-21
-chr1	105	110	q2.2	20	-	1	chr1	105	115	2.3	20	+	0
-chr1	105	110	q2.2	20	-	1	chr1	98	108	2.2	20	+	0
 chr1	105	110	q2.2	20	-	2	chr1	95	110	3.8	20	-	0
+chr1	105	110	q2.2	20	-	1	chr1	98	108	2.2	20	+	0
+chr1	105	110	q2.2	20	-	1	chr1	105	115	2.3	20	+	0
 chr1	105	110	q2.2	20	-	2	chr1	90	105	3.7	20	+	-1
 chr1	105	110	q2.2	20	-	1	chr1	95	105	2.1	20	+	-1
 chr1	105	110	q2.2	20	-	2	chr1	110	115	3.9	20	+	1
@@ -500,7 +501,7 @@ rm obs exp
 
 echo "    kclosest.t31...\c"
 echo \
-"chr1	100	110	q2.1	20	+	1	chr1	95	105	2.1	20	+	0
+"chr1	100	110	q2.1	20	+	2	chr1	90	105	3.7	20	+	0
 chr1	100	110	q2.1	20	+	2	chr1	110	115	3.9	20	+	1
 chr1	100	110	q2.1	20	+	1	chr1	120	130	2.4	20	+	11
 chr1	100	110	q2.1	20	+	2	chr1	70	80	3.6	20	+	-21
@@ -509,8 +510,8 @@ chr1	100	110	q2.1	20	+	1	chr1	140	160	2.5	20	+	31
 chr1	100	110	q2.1	20	+	2	chr1	45	60	3.3	20	-	-41
 chr1	100	110	q2.1	20	+	2	chr1	30	40	3.2	20	+	-61
 chr1	100	110	q2.1	20	+	2	chr1	10	20	3.1	20	-	-81
-chr1	105	110	q2.2	20	-	1	chr1	98	108	2.2	20	+	0
-chr1	105	110	q2.2	20	-	1	chr1	95	105	2.1	20	+	-1
+chr1	105	110	q2.2	20	-	2	chr1	95	110	3.8	20	-	0
+chr1	105	110	q2.2	20	-	2	chr1	90	105	3.7	20	+	-1
 chr1	105	110	q2.2	20	-	1	chr1	120	130	2.4	20	+	11
 chr1	105	110	q2.2	20	-	2	chr1	130	140	3.11	20	+	21
 chr1	105	110	q2.2	20	-	2	chr1	70	80	3.6	20	+	-26
@@ -526,7 +527,7 @@ rm obs exp
 
 echo "    kclosest.t32...\c"
 echo \
-"chr1	100	110	q2.1	20	+	2	chr1	95	110	3.8	20	-	0
+"chr1	100	110	q2.1	20	+	1	chr1	105	115	2.3	20	+	0
 chr1	100	110	q2.1	20	+	2	chr1	110	115	3.9	20	+	1
 chr1	100	110	q2.1	20	+	2	chr1	120	130	3.10	20	-	11
 chr1	100	110	q2.1	20	+	2	chr1	130	140	3.11	20	+	21
@@ -535,7 +536,7 @@ chr1	100	110	q2.1	20	+	1	chr1	140	150	2.7	20	+	31
 chr1	100	110	q2.1	20	+	2	chr1	150	155	3.14	20	-	41
 chr1	100	110	q2.1	20	+	2	chr1	170	180	3.15	20	+	61
 chr1	100	110	q2.1	20	+	2	chr1	190	200	3.16	20	-	81
-chr1	105	110	q2.2	20	-	2	chr1	95	110	3.8	20	-	0
+chr1	105	110	q2.2	20	-	1	chr1	105	115	2.3	20	+	0
 chr1	105	110	q2.2	20	-	2	chr1	110	115	3.9	20	+	1
 chr1	105	110	q2.2	20	-	2	chr1	120	130	3.10	20	-	11
 chr1	105	110	q2.2	20	-	2	chr1	130	140	3.11	20	+	21
@@ -648,3 +649,6 @@ chr1	105	110	q2.2	20	-	chr1	30	40	3.2	20	+	66" > exp
 $BT closest -a q2.bed -b d3.bed -k 5  -D b -t first -fd > obs
 check obs exp
 rm obs exp
+
+
+
diff --git a/test/intersect/test-intersect.sh b/test/intersect/test-intersect.sh
index 7af4d715f934e95c66c0c6e2c9d5e3d7ead987d8..42aa93a8e31615e0d69a7fd05a2629c123d2e0f3 100644
--- a/test/intersect/test-intersect.sh
+++ b/test/intersect/test-intersect.sh
@@ -502,8 +502,8 @@ $BT intersect -a a.bed -b b.bed -f 1.00001 2>&1 > /dev/null | cat - | head -2 |
 check exp obs
 rm exp obs
 
-##################################################################bug167_strandSweep.bed
-#  Test that -s works with chromsweep
+##################################################################
+#  bug167_strandSweep.bed
 ##################################################################
 echo "    intersect.t41...\c"
 echo \
@@ -512,8 +512,8 @@ $BT intersect -a bug167_strandSweep.bed -b bug167_strandSweep.bed -sorted -s -wa
 check exp obs
 rm exp obs
 
-##################################################################bug167_strandSweep.bed
-#  Test that -S works with chromsweep
+##################################################################
+#  bug167_strandSweep.bed
 ##################################################################
 echo "    intersect.t42...\c"
 echo \
@@ -525,6 +525,19 @@ rm exp obs
 rm one_block.bam two_blocks.bam three_blocks.bam
 
 
+##################################################################
+# Bug 187 0 length records
+##################################################################
+echo "    intersect.t43...\c"
+echo \
+"chr7	33059403	33059403	chr7	33059336	33060883	NT5C3A	intron	0
+chr7	33059403	33059403	chr7	32599076	33069221	NAq	intron	0" > exp
+$BT intersect -a bug187_a.bed -b bug187_b.bed -wao > obs
+check exp obs
+rm exp obs
+
+
+
 cd multi_intersect
 bash test-multi_intersect.sh
 cd ..