Add some logging statements
Avoid NullPointerException
Reconnect on close