Common functions for server and client