Refactored getPort() code.