fixed the server problem - now closes gracefully