fixed issues with port variable being shared incorrectly