added client onClose fixes, added more tests