Fix segfaults on client and server