Properly close a port