Added closePort function and class destructor