Working out logic for borders