separating out into server and client functionality