Fix intermediate ports calculation