refactor newPubSocket func for further work