more tweaking and cleaning up in preparation for global signed L1-distance function