Added conditional to check for undefined portal ID