Fixing a bug where app can crash if the ports are still being used