PR #15 + connectionLost signal

Hi,

I've taken the liberty to rebase the code in Pull Request #15 and implement what @rbann said in the same PR. We are stuck with this problem in production, so would like to get it merged ASAP. Please let me know if there is anything more that I can do to get this accepted.

Best regards,