Fix for boundary spinning

This also contains some code that will make it easier to define arbitrary boundaries for lines.