fixed bugs dealing with near line segments and restructured stuff