Improved port determination.