Fix for #146 and #150. closing socket and entangled variables
Merge remote-tracking branch 'origin/gh-150-146-socket-test'