Added better closing of the preview server.