Explicitly shut down server

Fix #519
Fix #520