Restructured border code to make more sense