Fix closing issues and clientID specification

As per issues #55 and #56.

I have not been able to create test cases yet but I can confirm this works with the client code we have developed internally