deal with missing closing boundary

@bf4 @jeremy
Need to explain the intent behind this implementation. The code itself does not communicate what it's doing or why. It's just a pile of spaghetti.