Added a sanity check to walk_perimeter