Added tests

Also refactored reconnect functionality into seperate method to enable
testing