revise client, server to close cleanly