added more advanced port detection, and a fail safe to not crash the game if no port is found or it tries to open a port that doesn't exist