make sockfd available to server app. fixed several memory leaks