Improvements to portal detection and set

Cut down on for loop use and struct use.