refactor code for BSIM sockets