added code to distiguish between server and client