potentially fixes #14, fixes #15 by explicitly listening on 'close' of res

After some testing I think this fixes #14 and #15.  Please review and see if this brings up some other issues.