Move generate_port() closer to when it will be used