Added perimeter scanning algorithm for interiors, fixed issues with outer perimeter scanning.  Currently contains lots of debug output.